PostgreSQL Tutorial: PostgreSQL Configuring Remote Connections

Two configuration information are required, one for postgreSQL remote connection configuration and postgreSQL log configuration.

The main configuration of PostgreSQL is placed in the data directory, postgresql.confas well as pg_hba.confthe configuration file

These configuration files are placed in

# 这个目录下
/var/lib/pgsql/12/data

image.png

As you can see in the picture above, the core files of postgreSQL all belong to the postgres user. When operating, try not to use the root user. This can easily lead to pitfalls. Try to switch to the postgres user first.

Remote connection configuration

PostgreSQL does not support remote connections by default. This is almost the same as MySQL.

  • MySQL mysql.userusually uses the grant command to add users.
  • PostgreSQL needs to be modified based on the configuration file to specify whether the user can connect remotely.

Go directly to modify pg_hba.confthe configuration file

Writing templates for users and corresponding databases and connection methods
image.png

# 第一块
local:代表本地连接,host代表可以指定连接的ADDRESS
# 第二块
database编写数据库名,如果写all,代表所有库都可以连接
# 第三块
user编写连接的用户,可以写all,代表所有用户
# 第四块
address代表那些IP地址可以连接
# 第五块
method加密方式,这块不用过多关注,直接md5
# 直接来个痛快的配置吗,允许任意地址的全部用户连接所有数据库
host    all             all             0.0.0.0/0               md5

image.png

In order to achieve remote connection, in addition to this configuration at the user level, a configuration must be modified for the service level.

The service level configuration is postgresql.conf
image.png
found by default. PGSQL only allows localhostconnections. Configuring it directly *can solve the problem.
image.png

Remember, in order to take effect, you must restart

# postgres密码不管,直接root用户
sudo systemctl restart postgresql-12

Guess you like

Origin blog.csdn.net/a772304419/article/details/132921686