Windows上Navicat工具远程连接PostgreSQL数据库
首先,在pgdata(也就是在安装pg时指定的存放数据的文件见中)文件夹中,找到pg_hba.conf文件,在文件最后写入下面的内容:
host all all 0.0.0.0/0 trust
接着,在pgdata文件夹中,找到postgresql.conf为文件,并修改下面的内容:
listen_addresses = '*' #允许任何的ip地址监听,并保存
最后,重新启动PostgreSQL数据库,然后在Navicat中进行连接配置
systemctl restart postgresql-12.service #重新启动pg数据库
采用yum方式安装的PostgreSQL,默认路径是:/var/lib/pgsql/12/data
可以通过如下方法进行查看:
[root@docker ~]# systemctl status postgresql-12.service
● postgresql-12.service - PostgreSQL 12 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-12.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2020-07-27 11:42:02 CST; 2h 34min ago
Docs: https://www.postgresql.org/docs/12/static/
Process: 1628 ExecStartPre=/usr/pgsql-12/bin/postgresql-12-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
Main PID: 1635 (postmaster)
CGroup: /system.slice/postgresql-12.service
├─1635 /usr/pgsql-12/bin/postmaster -D /var/lib/pgsql/12/data/ # 注意看这一行
├─1637 postgres: logger
├─1639 postgres: checkpointer
├─1640 postgres: background writer
├─1641 postgres: walwriter
├─1642 postgres: autovacuum launcher
├─1643 postgres: stats collector
├─1644 postgres: logical replication launcher
└─1958 postgres: postgres runoobdb [local] idle
Jul 27 11:42:02 docker.domain.com systemd[1]: Starting PostgreSQL 12 database server...
Jul 27 11:42:02 docker.domain.com postmaster[1635]: 2020-07-27 11:42:02.505 CST [1635] LOG: starting PostgreSQL 12.3 on x86_64-pc-linux-gnu, compiled by gcc (G...), 64-bit
Jul 27 11:42:02 docker.domain.com postmaster[1635]: 2020-07-27 11:42:02.506 CST [1635] LOG: listening on IPv4 address "127.0.0.1", port 5432
Jul 27 11:42:02 docker.domain.com postmaster[1635]: 2020-07-27 11:42:02.506 CST [1635] LOG: could not bind IPv6 address "::1": Cannot assign requested address
Jul 27 11:42:02 docker.domain.com postmaster[1635]: 2020-07-27 11:42:02.506 CST [1635] HINT: Is another postmaster already running on port 5432? If not, wait a...nd retry.
Jul 27 11:42:02 docker.domain.com postmaster[1635]: 2020-07-27 11:42:02.507 CST [1635] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
Jul 27 11:42:02 docker.domain.com postmaster[1635]: 2020-07-27 11:42:02.508 CST [1635] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
Jul 27 11:42:02 docker.domain.com postmaster[1635]: 2020-07-27 11:42:02.516 CST [1635] LOG: redirecting log output to logging collector process
Jul 27 11:42:02 docker.domain.com postmaster[1635]: 2020-07-27 11:42:02.516 CST [1635] HINT: Future log output will appear in directory "log".
Jul 27 11:42:02 docker.domain.com systemd[1]: Started PostgreSQL 12 database server.
Hint: Some lines were ellipsized, use -l to show in full.
重新启动pg数据库后再次查看状态
[root@docker ~]# systemctl status postgresql-12.service
● postgresql-12.service - PostgreSQL 12 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-12.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2020-07-27 14:20:17 CST; 1s ago
Docs: https://www.postgresql.org/docs/12/static/
Process: 2146 ExecStartPre=/usr/pgsql-12/bin/postgresql-12-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
Main PID: 2153 (postmaster)
CGroup: /system.slice/postgresql-12.service
├─2153 /usr/pgsql-12/bin/postmaster -D /var/lib/pgsql/12/data/
├─2157 postgres: logger
├─2159 postgres: checkpointer
├─2160 postgres: background writer
├─2161 postgres: walwriter
├─2162 postgres: autovacuum launcher
├─2163 postgres: stats collector
└─2164 postgres: logical replication launcher
Jul 27 14:20:17 docker.domain.com systemd[1]: Starting PostgreSQL 12 database server...
Jul 27 14:20:17 docker.domain.com postmaster[2153]: 2020-07-27 14:20:17.902 CST [2153] LOG: starting PostgreSQL 12.3 on x86_64-pc-linux-gnu, compiled by gcc (G...), 64-bit
Jul 27 14:20:17 docker.domain.com postmaster[2153]: 2020-07-27 14:20:17.902 CST [2153] LOG: listening on IPv4 address "0.0.0.0", port 5432
Jul 27 14:20:17 docker.domain.com postmaster[2153]: 2020-07-27 14:20:17.902 CST [2153] LOG: listening on IPv6 address "::", port 5432
Jul 27 14:20:17 docker.domain.com postmaster[2153]: 2020-07-27 14:20:17.903 CST [2153] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
Jul 27 14:20:17 docker.domain.com postmaster[2153]: 2020-07-27 14:20:17.904 CST [2153] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
Jul 27 14:20:17 docker.domain.com postmaster[2153]: 2020-07-27 14:20:17.913 CST [2153] LOG: redirecting log output to logging collector process
Jul 27 14:20:17 docker.domain.com postmaster[2153]: 2020-07-27 14:20:17.913 CST [2153] HINT: Future log output will appear in directory "log".
Jul 27 14:20:17 docker.domain.com systemd[1]: Started PostgreSQL 12 database server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@docker ~]# ss -tulnp | grep 5432
tcp LISTEN 0 128 *:5432 *:* users:(("postmaster",pid=2153,fd=3))
tcp LISTEN 0 128 [::]:5432 [::]:* users:(("postmaster",pid=2153,fd=4))