The postgresql-server version in centos 6.4 is 8.4.13.
1. Install PostgreSQL Server:
$Yum groupinstall "PostgreSQL database server"
The default installation directory is/var/lib/pgsql. The Postgres user and group will be created during the installation process. After the installation is complete, you can set the service PostgreSQL to self-start:
$Chkconfig PostgreSQL on
2. Start the postgresql service. Before that, initialize:
$ Service PostgreSQL initdbinitializing Database : [OK] $ ls /Var/lib/pgsql/data/ Total 76 Drwx ------. 5 Postgres 4096 May 25 09 : 53 Basedrwx ------. 2 Postgres 4096 May 25 10 : 07 Globaldrwx ------. 2 Postgres4096 May 25 09 : 53 Pg_clog -RW -------. 1 Postgres 3411 May 25 09 : 53 Pg_hba. Conf -RW -------. 1 Postgres 1631 May 25 09 : 53 Pg_ident. Confdrwx ------. 2 Postgres 4096 May 25 10 : 06 Pg_logdrwx ------. 4 Postgres 4096 May 25 09 : 53 Pg_multixactdrwx ------. 2 Postgres 4096 May 25 10 : 07 Pg_stat_tmpdrwx ------. 2 Postgres 4096 May 25 09 : 53 Pg_subtransdrwx ------. 2 Postgres 4096 May 25 09 : 53 Pg_tblspcdrwx ------. 2 Postgres 4096 May 25 09 : 53 Pg_twophase -RW -------. 1 Postgres 4 May25 09 : 53 Pg_versiondrwx ------. 3 Postgres 4096 May 25 09 : 53 Pg_xlog -RW -------. 1 Postgres 16886 May 25 09 :53 PostgreSQL. Conf -RW -------. 1 Postgres 57 May 25 10 : 06 Postmaster. Opts $ service PostgreSQL startstarting postgresql service : [OK]
3. Modify the listening address and port of PostgreSQL. conf:
$ CAT/var/lib/pgsql/data/PostgreSQL.Conf......#-Connection settings-Listen_addresses ='*'#What IP address (es) to listen on; # comma-separated list of addresses; # defaults to 'localhost', '*' = all # (change requires restart)Port =5432#(Change requires restart)......
4. ModifyPg_cmd.conf: configure the client connection permission. For details about how to configure pg_cmd.conf, refer 《Analysis of pg_cmd.conf File.
$ CAT/var/lib/pgsql/data/pg_hba . Conf # Type Database User CIDR-ADDRESS method # "local" is for Unix domain socket connections only Local All all ident # IPv4 local connections: Host All all 127.0 . 0.1 / 32 Ident # IPv6 local connections: Host All :: 1 / 128 Identhost all 192.168 . 12.0 / 24 MD5
5. Switch to Postgres user and modify the password of Postgres, the default role of the database (the default password is blank ):
$ Su-Postgres $ psqlpostgres=#\ Password SEnter new password:Enter it again:
6. After setting all posgresql service parameters, reload the configuration parameters:
$ Pg_ctl reload
7. Modify iptables rules to allow remote connection to port 5432:
$ CAT/etc/sysconfig/ Iptables # Firewall Configuration written by system-config-firewall # manual customization of this file is not recommended. * Filter : Input Accept [ 0 :0 ] : Forward Accept [ 0 : 0 ] : Output Accept [ 0 : 0 ] -A input-M state -- State established, related-J Accept -A input-p icmp-J Accept -A input-I lo-J Accept -A input-M state -- state new-m tcp-p tcp -- dport 22 -J Accept -A input-M state -- state new-m tcp-p tcp -- dport 5432 -J Accept -A input-J reject -- reject-with ICMP-host- Prohibited -A forward-J reject -- reject-with ICMP-host- Prohibitedcommit $ service iptables restart
8. Finally, you can install pgadmin on other Windows clients and use the Postgres role to remotely manage the server: