Bit Focus

Configurations Trouble Shooting for Postgres 9 on CentOS 7

Posted at 2018-04-01 07:12:26 | Updated at 2018-04-01 07:15:38

0. Change the Data Directory

For some reason the -D or --pgdata arguments passed to initdb command doesn't work. The solution is modifying /etc/init.d/postgres-X.Y, changing this line


And run initdb again (of course -D or --pgdata is not necessary any more).

1. Access Control

The network access is set as ident after installation. If you want to use username/password to login the database, which is much easier (but may have some security problems as you need to keep the password carefully), you need to change ... well the file name is not explicitly documented. You are supposed to execute the following command to find it out.

show hba_file

Postgres will give you the path where the configure file locates (usually a pg_hba.conf file). Open that file, modifying this line

# host  all    all   ident
# change it to
host    all    all   password

Clarification: you must use the postgres user (the UNIX user) to login your localhost Postgres server to execute show hba_file, as all other users are required to provide the ident in this case.

You might have noticed that the IP address is in that file. This address means all connections from (the localhost) are required to provide the username/password. If you have several hosts in your internal network, you may need change that address into this (assume your internal network has addresses in the pattern of 192.168.*.*)

host    all    all   password

However by default the Postgres binds only the localhost so clients from other hosts are unable to connect in the first place. In short, there is another file postgresql.conf, which is usually in the same directory of the hba_file, should be taken care of. Change this line in postgresql.conf

listen_addresses = 'localhost,192.168.x.x'

Use comma to separate adapter addresses, and replace 192.168.x.x to the address of the Postgres server.

Post tags:   Postgres  CentOS

Leave a comment:

Creative Commons License Your comment will be licensed under
CC-NC-ND 3.0

. Back to Bit Focus
NijiPress - Copyright (C) Neuron Teckid @ Bit Focus
About this site