Get the App
SLTechnology News&Howtos  ›  Database  › 

Centos73 postgresql9.6.2rpm installation

Shulou Source: shulou.com Published: 2022-06-01 14:12:44 09月13日 Update

Postgresql9.6.2 rpm installation

1. Install the RPM package

Rpm-ivf postgresql96-libs-9.6.2-2PGDG.rhel7.x86_64.rpm

Rpm-ivf postgresql96-9.6.2-2PGDG.rhel7.x86_64.rpm

Rpm-ivf postgresql96-server-9.6.2-2PGDG.rhel7.x86_64.rpm

Rpm-ivf postgresql96-contrib-9.6.2-2PGDG.rhel7.x86_64.rpm

Rpm-ivf postgresql96-devel-9.6.2-2PGDG.rhel7.x86_64.rpm

2. Initialize the PostgreSQL database

/ usr/pgsql-9.6/bin/postgresql96-setup initdb

3. Start the service

Systemctl start postgresql-9.6.service

4. Add the PostgreSQL service to the startup list

Systemctl enable postgresql-9.6.service

5. Modify the password of the PostgreSQL database user postgres (note that it is not the linux system account)

PostgreSQL database default will create a postgres database user as the database administrator, the default password is empty, we need to change to the specified password, here set to 'postgres'.

# su-postgres switches users, and the prompt will change to'- bash-4.2 $'after execution

$psql logs in to the database, and the prompt changes to 'postgres=#' after execution

Postgres=# alter user postgres with password 'postgres'

ALTER ROLE

Postgres=# select * from pg_shadow

6. Test database

6.1 create a test database

Postgres=# create database test

6.2. switch to david database

#\ c test

6.3. Create a test table

Test=# create table T1 (id integer, name text)

6.4. Insert test data

Test=# insert into T1 values (1memery T1')

INSERT 0 1

Test=#

6.5. Select data

Test=# select * from T1

Id | name

-- +-

1 | T1

(1 row)

Test=#

The test is complete and the RPM package is installed successfully.

7. Modify the password of the linux system user postgres

By default, the PostgreSQL database creates a linux system user, postgres, and sets the system user's password to postgres through the passwd command.

# passwd postgres

8. Modify PostgresSQL database configuration to achieve remote access

8.1 modify the postgresql.conf file

# vim / var/lib/pgsql/9.6/data/postgresql.conf

If you want PostgreSQL to listen on the entire network, remove the # before listen_addresses and change listen_addresses = 'localhost' to listen_addresses =' *'

8.2 modify client authentication profile pg_hba.conf

Add the IP address or address field that requires remote access to the database to the file.

# vim / var/lib/pgsql/9.6/data/pg_hba.conf

Add in "# IPv4 local connections"

Host all all 127.0.0.1/32 ident

Host all all 192.168.1.199/24 md5

9. Restart the service for the settings to take effect

# systemctl restart postgresql-9.6.service

10. Remote testing can be accessed through cmd using client tools or machines with postgresql

Psql-U postgres-h 192.168.1.199

Question:

1), configure to support remote connection

$vim / var/lib/pgsql/9.6/data/pg_hba.conf

# directly configure to not limit IP, that is, 0.0.0.0. Note: / must also be followed by 0 limit! #

Change 127.0.0.1 Compact 32 to 0.0.0.0 Universe 0

By the way, change the ident of the method attribute of this line to trust, otherwise the user will report the error of postgres ident authentication failure when connecting remotely with the client tool.

2) remove the version number to start the service

Cd / usr/lib/systemd/system

Ln-s postgresql-9.6.service postgresql.service

You can use it later.

Systemctl start postgresql

Tags: Data database user test password system service configuration customer client file creation address tool prompt switch prompt authentication success command Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Tech Info Docker Redmi OPPO Reno