0. Change the Data Directory
For some reason the
--pgdata arguments passed to
initdb command doesn't work. The solution is modifying
/etc/init.d/postgres-X.Y, changing this line
initdb again (of course
--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.
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 127.0.0.1/32 ident
# change it to
host all all 127.0.0.1/32 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
127.0.0.1 in that file. This address means all connections from
127.0.0.1 (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
host all all 192.168.0.0/16 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.