Running PostgreSQL
After installing PostgreSQL, you can initialize, start, and log in to the database, configure the database user account and password, and modify the configuration file to check whether the database is running properly.
- Initialize the database.
Perform this step as the postgres user.
- Switch to the postgres user.
1su - postgres
- Open the environment variable file.
1vim .bash_profile - Press i to enter the insert mode and add the public library path at the bottom of the environment variable file.
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/pgsql/lib

- Press Esc, type :wq!, and press Enter to save the file and exit.
- Make the modification take effect.
1source .bash_profile
- Initialize the database.
1/usr/local/pgsql/bin/initdb -D /data/pgsql

- Switch to the postgres user.
- Start the database.
- Start the PostgreSQL database.
1/usr/local/pgsql/bin/pg_ctl -D /data/pgsql -l logfile start

- Check whether the PostgreSQL database process is started properly.
1ps -ef | grep postgres

As shown in the preceding figure, related PostgreSQL processes have been started.
- Start the PostgreSQL database.
- Log in to the database.
1/usr/local/pgsql/bin/psql -U postgres

You do not have to enter the password for the first login.
- Change the password of the database account.
After login, set the password of the postgres user.
1alter user postgres with password '123456';

- Exit the database.
1\q

- Stop the database.
1/usr/local/pgsql/bin/pg_ctl -D /data/pgsql -l logfile stop

- Modify the database configuration file.
- Open /data /pg_hba.conf.
1vim /data/pgsql/pg_hba.conf - Press i to enter the insert mode and add the following content to allow non-local access. Replace the example IP address with the actual one.
host all all 192.168.202.0/24 trust

- Press Esc, type :wq!, and press Enter to save the file and exit.
- If the database service is started, run the following command to reload the configuration file after the configuration is complete: If the database service is stopped, restart the database service for the modification to take effect.
1/usr/local/pgsql/bin/pg_ctl reload -D /data/pgsql

- Open /data /pg_hba.conf.
Parent topic: Installation Guide