深度linux安装postgresql_Linux 上安装 PostgreSQL

我这里使用的rpm方式,参考链接使用的是tar.gz的方式,看个人需求的吧,没有网络可以使用tar.gz下载好进行安装。

1、Linux查看版本当前操作系统发行信:cat /etc/centos-release。

1 [root@slaver1 ~]# cat /etc/centos-release2 CentOS Linux release 7.7.1908(Core)3 [root@slaver1 ~]#

2、Linux查看版本当前操作系统内核信息:uname -a。

1 [root@slaver1 ~]# uname -a2 Linux slaver1 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux3 [root@slaver1 ~]#

63fc00f851d3bd2a32c5521f1d64a0ea.png

选择自己是什么操作系统, 然后选择对应得即可。

54c418ea0898a7e7ef7596638ed71183.png

我的是Centos操作系统,如下所示:

3735f80c9e95973660181434f1d873cd.png

然后版本,操作系统版本,多少位的。

f56e47e95427ae33fac7459f50091d4e.png

4、执行yum下载命令,将rpm包下载下来,如下所示:

1 [root@slaver1 package]# yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

2 已加载插件:fastestmirror, langpacks3 pgdg-redhat-repo-latest.noarch.rpm | 6.5 kB 00:00:00

4 正在检查 /var/tmp/yum-root-OuHt4M/pgdg-redhat-repo-latest.noarch.rpm: pgdg-redhat-repo-42.0-11.noarch5 /var/tmp/yum-root-OuHt4M/pgdg-redhat-repo-latest.noarch.rpm 将被安装6 正在解决依赖关系7 -->正在检查事务8 ---> 软件包 pgdg-redhat-repo.noarch.0.42.0-11将被 安装9 -->解决依赖关系完成10

11 依赖关系解决12

13 ================================================================================================================================================================================================================================

14 Package 架构 版本 源 大小15 ================================================================================================================================================================================================================================

16 正在安装:17 pgdg-redhat-repo noarch 42.0-11 /pgdg-redhat-repo-latest.noarch 11k18

19 事务概要20 ================================================================================================================================================================================================================================

21 安装 1软件包22

23 总计:11k24 安装大小:11k25 Is this ok [y/d/N]: y26 Downloading packages:27 Running transaction check28 Running transaction test29 Transaction test succeeded30 Running transaction31 正在安装 : pgdg-redhat-repo-42.0-11.noarch 1/1

32 验证中 : pgdg-redhat-repo-42.0-11.noarch 1/1

33

34 已安装:35 pgdg-redhat-repo.noarch 0:42.0-11

36

37 完毕!

5、然后开始安装postgresql服务器端,如下所示:

1 [root@slaver1 package]# yum install postgresql10-server2 已加载插件:fastestmirror, langpacks3 /var/run/yum.pid 已被锁定,PID 为 78607的另一个程序正在运行。4 Another app is currently holding the yum lock; waiting forit to exit...5 另一个应用程序是:PackageKit6 内存: 31 M RSS (451MB VSZ)7 已启动: Thu Aug 13 09:51:43 2020 - 00:11之前8 状态 :睡眠中,进程ID:78607

9 Another app is currently holding the yum lock; waiting forit to exit...10 另一个应用程序是:PackageKit11 内存: 32 M RSS (452MB VSZ)12 已启动: Thu Aug 13 09:51:43 2020 - 00:13之前13 状态 :睡眠中,进程ID:78607

14 Another app is currently holding the yum lock; waiting forit to exit...15 另一个应用程序是:PackageKit16 内存: 32 M RSS (452MB VSZ)17 已启动: Thu Aug 13 09:51:43 2020 - 00:15之前18 状态 :睡眠中,进程ID:78607

19 Another app is currently holding the yum lock; waiting forit to exit...20 另一个应用程序是:PackageKit21 内存: 32 M RSS (452MB VSZ)22 已启动: Thu Aug 13 09:51:43 2020 - 00:17之前23 状态 :睡眠中,进程ID:78607

24 Another app is currently holding the yum lock; waiting forit to exit...25 另一个应用程序是:PackageKit26 内存: 32 M RSS (452MB VSZ)27 已启动: Thu Aug 13 09:51:43 2020 - 00:19之前28 状态 :睡眠中,进程ID:78607

29 Another app is currently holding the yum lock; waiting forit to exit...30 另一个应用程序是:PackageKit31 内存: 32 M RSS (452MB VSZ)32 已启动: Thu Aug 13 09:51:43 2020 - 00:21之前33 状态 :睡眠中,进程ID:78607

34 Another app is currently holding the yum lock; waiting forit to exit...35 另一个应用程序是:PackageKit36 内存: 38 M RSS (459MB VSZ)37 已启动: Thu Aug 13 09:51:43 2020 - 00:23之前38 状态 :运行中,进程ID:78607

39 Another app is currently holding the yum lock; waiting forit to exit...40 另一个应用程序是:PackageKit41 内存:174 M RSS (594MB VSZ)42 已启动: Thu Aug 13 09:51:43 2020 - 00:25之前43 状态 :运行中,进程ID:78607

44 Another app is currently holding the yum lock; waiting forit to exit...45 另一个应用程序是:PackageKit46 内存:265 M RSS (685MB VSZ)47 已启动: Thu Aug 13 09:51:43 2020 - 00:27之前48 状态 :运行中,进程ID:78607

49 Another app is currently holding the yum lock; waiting forit to exit...50 另一个应用程序是:PackageKit51 内存:265 M RSS (685MB VSZ)52 已启动: Thu Aug 13 09:51:43 2020 - 00:29之前53 状态 :睡眠中,进程ID:78607

54 Another app is currently holding the yum lock; waiting forit to exit...55 另一个应用程序是:PackageKit56 内存:265 M RSS (685MB VSZ)57 已启动: Thu Aug 13 09:51:43 2020 - 00:31之前58 状态 :睡眠中,进程ID:78607

59 Loading mirror speeds fromcached hostfile60 * base: mirrors.aliyun.com61 * epel: mirrors.yun-idc.com62 *extras: mirror.bit.edu.cn63 *updates: mirrors.aliyun.com64 正在解决依赖关系65 -->正在检查事务66 ---> 软件包 postgresql10-server.x86_64.0.10.13-1PGDG.rhel7 将被 安装67 --> 正在处理依赖关系 postgresql10-libs(x86-64) = 10.13-1PGDG.rhel7,它被软件包 postgresql10-server-10.13-1PGDG.rhel7.x86_64 需要68 --> 正在处理依赖关系 postgresql10(x86-64) = 10.13-1PGDG.rhel7,它被软件包 postgresql10-server-10.13-1PGDG.rhel7.x86_64 需要69 --> 正在处理依赖关系 libpq.so.5()(64bit),它被软件包 postgresql10-server-10.13-1PGDG.rhel7.x86_64 需要70 -->正在检查事务71 ---> 软件包 postgresql10.x86_64.0.10.13-1PGDG.rhel7 将被 安装72 ---> 软件包 postgresql10-libs.x86_64.0.10.13-1PGDG.rhel7 将被 安装73 -->解决依赖关系完成74

75 依赖关系解决76

77 ================================================================================================================================================================================================================================

78 Package 架构 版本 源 大小79 ================================================================================================================================================================================================================================

80 正在安装:81 postgresql10-server x86_64 10.13-1PGDG.rhel7 pgdg10 4.5M82 为依赖而安装:83 postgresql10 x86_64 10.13-1PGDG.rhel7 pgdg10 1.6M84 postgresql10-libs x86_64 10.13-1PGDG.rhel7 pgdg10 357k85

86 事务概要87 ================================================================================================================================================================================================================================

88 安装 1 软件包 (+2依赖软件包)89

90 总下载量:6.5M91 安装大小:28M92 Is this ok [y/d/N]: y93 Downloading packages:94 警告:/var/cache/yum/x86_64/7/pgdg10/packages/postgresql10-libs-10.13-1PGDG.rhel7.x86_64.rpm: 头V4 DSA/SHA1 Signature, 密钥 ID 442df0f8: NOKEY ] 128 kB/s | 416 kB 00:00:48ETA95 postgresql10-libs-10.13-1PGDG.rhel7.x86_64.rpm 的公钥尚未安装96 (1/3): postgresql10-libs-10.13-1PGDG.rhel7.x86_64.rpm | 357 kB 00:00:05

97 (2/3): postgresql10-10.13-1PGDG.rhel7.x86_64.rpm | 1.6 MB 00:02:40

98 (3/3): postgresql10-server-10.13-1PGDG.rhel7.x86_64.rpm | 4.5 MB 00:02:44

99 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

100 总计 39 kB/s | 6.5 MB 00:02:50

101 从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG 检索密钥

102 导入 GPG key 0x442DF0F8:103 用户ID : "PostgreSQL RPM Building Project "

104 指纹 : 68c9 e2b9 1a37 d136 fe74 d176 1f16 d2e1 442d f0f8105 软件包 : pgdg-redhat-repo-42.0-11.noarch (@/pgdg-redhat-repo-latest.noarch)106 来自 : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG107 是否继续?[y/N]:y108 Running transaction check109 Running transaction test110 Transaction test succeeded111 Running transaction112 正在安装 : postgresql10-libs-10.13-1PGDG.rhel7.x86_64 1/3

113 正在安装 : postgresql10-10.13-1PGDG.rhel7.x86_64 2/3

114 正在安装 : postgresql10-server-10.13-1PGDG.rhel7.x86_64 3/3

115 验证中 : postgresql10-libs-10.13-1PGDG.rhel7.x86_64 1/3

116 验证中 : postgresql10-10.13-1PGDG.rhel7.x86_64 2/3

117 验证中 : postgresql10-server-10.13-1PGDG.rhel7.x86_64 3/3

118

119 已安装:120 postgresql10-server.x86_64 0:10.13-1PGDG.rhel7121

122 作为依赖被安装:123 postgresql10.x86_64 0:10.13-1PGDG.rhel7 postgresql10-libs.x86_64 0:10.13-1PGDG.rhel7124

125 完毕!126 [root@slaver1 package]#

6、开始初始化postgresql数据库,如下所示:

1 [root@slaver1 package]# /usr/pgsql-10/bin/postgresql-10-setup initdb2 Initializing database ... OK3

4 [root@slaver1 package]#

7、设置开机自启动,然后启动postgresql数据库,如下所示:

1 [root@slaver1 package]# systemctl enable postgresql-10

2 Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-10.service to /usr/lib/systemd/system/postgresql-10.service.3 [root@slaver1 package]# systemctl start postgresql-10

4 [root@slaver1 package]#

8、查看postgresql的相关进程,如下所示:

1 [root@slaver1 ~]# ps -ef |grep postgres2 postgres 79928 1 0 10:07 ? 00:00:00 /usr/pgsql-10/bin/postmaster -D /var/lib/pgsql/10/data/

3 postgres 79931 79928 0 10:07 ? 00:00:00postgres: logger process4 postgres 79933 79928 0 10:07 ? 00:00:00postgres: checkpointer process5 postgres 79934 79928 0 10:07 ? 00:00:00postgres: writer process6 postgres 79935 79928 0 10:07 ? 00:00:00postgres: wal writer process7 postgres 79936 79928 0 10:07 ? 00:00:00postgres: autovacuum launcher process8 postgres 79937 79928 0 10:07 ? 00:00:00postgres: stats collector process9 postgres 79938 79928 0 10:07 ? 00:00:00postgres: bgworker: logical replication launcher10 root 84515 78910 0 10:56 pts/4 00:00:00 grep --color=auto postgres11 [root@slaver1 ~]#

pgsql默认的端口号为5432,通过netstat命令或者lsof命令都可以看到监听情况:

1 [root@slaver1 ~]# lsof -i:5432

2 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME3 postmaste 79928 postgres 3u IPv6 6630830t0 TCP localhost:postgres (LISTEN)4 postmaste 79928 postgres 4u IPv4 6630840t0 TCP localhost:postgres (LISTEN)5 [root@slaver1 ~]# netstat -an | grep 5432

6 tcp 0 0 127.0.0.1:5432 0.0.0.0:*LISTEN7 tcp6 0 0 ::1:5432 :::*LISTEN8 unix 2 [ ACC ] STREAM LISTENING 663093 /var/run/postgresql/.s.PGSQL.5432

9 unix 2 [ ACC ] STREAM LISTENING 663095 /tmp/.s.PGSQL.5432

10 [root@slaver1 ~]#

现在可以看到pgsql默认监听的是localhost或127.0.0.1,目前只能本机访问,如果远程访问就连接不上了,具体的配置文件是data目录下的postgresql.conf,可以通过修改这个配置文件来调整各个参数,比如:listen_addresses可以修改绑定的地址,默认是localhost,port可以修改监听的端口号,默认是5432,max_connections可以修改最大客户端连接数量,默认是100等等。

注意:我这里才用的是默认的安装方式,就使用find命令查找了一下postgresql.conf的配置位置,然后进行修改:

1 [root@slaver1 /]# find -name postgresql.conf2 ./var/lib/pgsql/10/data/postgresql.conf3 ./usr/lib/tmpfiles.d/postgresql.conf4 [root@slaver1 /]# ll /var/lib/pgsql/10/data/

5 总用量 60

6 drwx------. 5 postgres postgres 41 8月 13 10:06 base

7 -rw-------. 1 postgres postgres 30 8月 13 10:07current_logfiles8 drwx------. 2 postgres postgres 4096 8月 13 10:20 global

9 drwx------. 2 postgres postgres 32 8月 13 10:07log10 drwx------. 2 postgres postgres 6 8月 13 10:06pg_commit_ts11 drwx------. 2 postgres postgres 6 8月 13 10:06pg_dynshmem12 -rw-------. 1 postgres postgres 4269 8月 13 10:06pg_hba.conf13 -rw-------. 1 postgres postgres 1636 8月 13 10:06pg_ident.conf14 drwx------. 4 postgres postgres 68 8月 13 10:12pg_logical15 drwx------. 4 postgres postgres 36 8月 13 10:06pg_multixact16 drwx------. 2 postgres postgres 18 8月 13 10:07pg_notify17 drwx------. 2 postgres postgres 6 8月 13 10:06pg_replslot18 drwx------. 2 postgres postgres 6 8月 13 10:06pg_serial19 drwx------. 2 postgres postgres 6 8月 13 10:06pg_snapshots20 drwx------. 2 postgres postgres 6 8月 13 10:06pg_stat21 drwx------. 2 postgres postgres 63 8月 13 11:01pg_stat_tmp22 drwx------. 2 postgres postgres 18 8月 13 10:06pg_subtrans23 drwx------. 2 postgres postgres 6 8月 13 10:06pg_tblspc24 drwx------. 2 postgres postgres 6 8月 13 10:06pg_twophase25 -rw-------. 1 postgres postgres 3 8月 13 10:06PG_VERSION26 drwx------. 3 postgres postgres 60 8月 13 10:06pg_wal27 drwx------. 2 postgres postgres 18 8月 13 10:06pg_xact28 -rw-------. 1 postgres postgres 88 8月 13 10:06postgresql.auto.conf29 -rw-------. 1 postgres postgres 22985 8月 13 10:06postgresql.conf30 -rw-------. 1 postgres postgres 58 8月 13 10:07postmaster.opts31 -rw-------. 1 postgres postgres 104 8月 13 10:07postmaster.pid32 [root@slaver1 /]# vim /var/lib/pgsql/10/data/postgresql.conf33 [root@slaver1 /]#

这里将localhost修改为192.168.110.133,如下所示:

b954e255d58db0defc131baeb10f7844.png

9、命令行界面简单操作,pgsql和mysql一样可以通过交互式提示符连接操作,连接方式如下:

1 [root@slaver1 ~]# psql -h 127.0.0.1 -d postgres -U postgres -p 5432

2 psql: 致命错误: 用户 "postgres"Ident 认证失败3 [root@slaver1 ~]#

修改认证文件[root@slaver1 ~]# vim /var/lib/pgsql/10/data/pg_hba.conf,登陆使用密码。把这个配置文件中的认证 METHOD的ident修改为trust,可以实现用账户和密码来访问数据库,即解决psql: 致命错误: 用户 "postgres" Ident 认证失败 这个问题)。

152ff9203b564bdd8cc682eecd313594.png

重启postgresql服务器使设置生效,如下所示:

注意:其中-h参数指定服务器地址,默认为127.0.0.1,默认不指定即可,-d指定连接之后选中的数据库,默认也是postgres,-U指定用户,默认是当前用户,-p 指定端口号,默认是"5432",其它更多的参数选项可以执行: ./bin/psql --help 查看。

1 [root@slaver1 ~]# psql -h 127.0.0.1 -d postgres -U postgres -p 5432

2 psql: could not connect to server: 拒绝连接3 Is the server running on host "127.0.0.1"and accepting4 TCP/IP connections on port 5432?

5 [root@slaver1 ~]# psql -h 192.168.110.133 -d postgres -U postgres -p 5432

6 psql: 致命错误: 没有用于主机 "192.168.110.133", 用户 "postgres", 数据库 "postgres", SSL 关闭 的 pg_hba.conf 记录7 [root@slaver1 ~]#

由于这里需要设置可以远程链接,将127.0.0.1的都改成自己ip地址,vim /var/lib/pgsql/10/data/pg_hba.conf,如下所示:

9510c67f81223dea5e9c25d793ee43d1.png

修改完毕,重启postgresql服务,如下所示:

1 [root@slaver1 ~]# systemctl stop postgresql-10

2 [root@slaver1 ~]# systemctl start postgresql-10

3 [root@slaver1 ~]# ps -ef |grep postgres4 postgres 86970 1 2 11:23 ? 00:00:00 /usr/pgsql-10/bin/postmaster -D /var/lib/pgsql/10/data/

5 postgres 86972 86970 0 11:23 ? 00:00:00postgres: logger process6 postgres 86974 86970 0 11:23 ? 00:00:00postgres: checkpointer process7 postgres 86975 86970 0 11:23 ? 00:00:00postgres: writer process8 postgres 86976 86970 0 11:23 ? 00:00:00postgres: wal writer process9 postgres 86977 86970 0 11:23 ? 00:00:00postgres: autovacuum launcher process10 postgres 86978 86970 0 11:23 ? 00:00:00postgres: stats collector process11 postgres 86979 86970 0 11:23 ? 00:00:00postgres: bgworker: logical replication launcher12 root 86982 78910 0 11:23 pts/4 00:00:00 grep --color=auto postgres13 [root@slaver1 ~]# lsof -i:5432

14 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME15 postmaste 86970 postgres 3u IPv4 7978660t0 TCP slaver1:postgres (LISTEN)16 [root@slaver1 ~]# ps -ef |grep postgres17 postgres 86970 1 0 11:23 ? 00:00:00 /usr/pgsql-10/bin/postmaster -D /var/lib/pgsql/10/data/

18 postgres 86972 86970 0 11:23 ? 00:00:00postgres: logger process19 postgres 86974 86970 0 11:23 ? 00:00:00postgres: checkpointer process20 postgres 86975 86970 0 11:23 ? 00:00:00postgres: writer process21 postgres 86976 86970 0 11:23 ? 00:00:00postgres: wal writer process22 postgres 86977 86970 0 11:23 ? 00:00:00postgres: autovacuum launcher process23 postgres 86978 86970 0 11:23 ? 00:00:00postgres: stats collector process24 postgres 86979 86970 0 11:23 ? 00:00:00postgres: bgworker: logical replication launcher25 root 86994 78910 0 11:24 pts/4 00:00:00 grep --color=auto postgres26 [root@slaver1 ~]#

然后使用命令行的方式连接postgresql数据库,如下所示:

1 [root@slaver1 ~]# psql -h 192.168.110.133 -d postgres -U postgres -p 5432

2 psql (9.2.24, 服务器 10.13)3 警告:psql 版本9.2, 服务器版本10.0.4 一些psql功能可能无法工作.5 输入 "help"来获取帮助信息.6

7 postgres=#

登录进去默认界面,命令提示符前面的就是当前的数据库,使用 \l 查看当前的数据库列表,如下所示:

1 [root@slaver1 ~]# psql -h 192.168.110.133 -d postgres -U postgres -p 5432

2 psql (9.2.24, 服务器 10.13)3 警告:psql 版本9.2, 服务器版本10.0.4 一些psql功能可能无法工作.5 输入 "help"来获取帮助信息.6

7 postgres=#8 postgres=# \l9 资料库列表10 名称 | 拥有者 | 字元编码 | 校对规则 | Ctype |存取权限11 -----------+----------+----------+-------------+-------------+-----------------------

12 postgres | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 |

13 template0 | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres +

14 | | | | | postgres=CTc/postgres15 template1 | postgres | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres +

16 | | | | | postgres=CTc/postgres17 (3行记录)18

19 postgres=#

创建一个简单的数据表可以执行下面的命令:

1 postgres=# CREATE TABLE student (2 postgres(# id integer NOT NULL,3 postgres(# name character(32),4 postgres(# number char(5),5 postgres(# CONSTRAINT student_pkey PRIMARY KEY (id)6 postgres(# );7 CREATE TABLE8 postgres=#9 postgres=#

创建表之后可以使用 \d student; 查看表的详细信息,如下:

1 postgres=# \d student;2 资料表 "public.student"

3 栏位 | 型别 |修饰词4 --------+---------------+--------

5 id | integer |非空6 name | character(32) |

7 number | character(5) |

8 索引:9 "student_pkey"PRIMARY KEY, btree (id)10

11 postgres=#

现在可以插入一条测试数据: INSERT INTO student (id, name, number) VALUES (1, '张三', '1023');

然后可以查询这条数据: SELECT * FROM student WHERE id=1;

1 postgres=# INSERT INTO student (id, name, number) VALUES (1, '张三', '1023');2 INSERT 0 1

3 postgres=# SELECT * FROM student WHERE id=1;4 id | name |number5 ----+------------------------------------+--------

6 1 | 张三 | 1023

7 (1行记录)8

9 postgres=#

最后可以执行 \q 退出交互式界面。

1 postgres=# \q2 [root@slaver1 ~]#

10、问题:致命错误: 用户 "postgres" Ident 认证失败?

说明:这个是由于没有配置远程访问且认证方式没改造成的,只需要更改使用账号密码认证即可。

解决:找到pg_hba.conf(find / -name pg_hba.conf),METHOD的ident修改为md5,且把ip端改为0.0.0.0/0,或者想要的IP地址即可。修改完成后直接reload即可。

11、METHOD指定如何处理客户端的认证。常用的有ident,md5,password,trust,reject

1)、ident是Linux下PostgreSQL默认的local认证方式,凡是能正确登录服务器的操作系统用户(注:不是数据库用户)就能使用本用户映射的数据库用户不需密码登录数据库。用户映射文件为pg_ident.conf,这个文件记录着与操作系统用户匹配的数据库用户,如果某操作系统用户在本文件中没有映射用户,则默认的映射数据库用户与操作系统用户同名。比如,服务器上有名为user1的操作系统用户,同时数据库上也有同名的数据库用户,user1登录操作系统后可以直接输入psql,以user1数据库用户身份登录数据库且不需密码。很多初学者都会遇到psql -U username登录数据库却出现“username ident 认证失败”的错误,明明数据库用户已经createuser。原因就在于此,使用了ident认证方式,却没有同名的操作系统用户或没有相应的映射用户。解决方案:第一种、在pg_ident.conf中添加映射用户;第二种、改变认证方式。

2)、METHOD指定如何处理客户端的认证,如下所示:

a、md5是常用的密码认证方式,如果你不使用ident,最好使用md5。密码是以md5形式传送给数据库,较安全,且不需建立同名的操作系统用户。

b、password是以明文密码传送给数据库,建议不要在生产环境中使用。

c、trust是只要知道数据库用户名就不需要密码或ident就能登录,建议不要在生产环境中使用。

d、reject是拒绝认证。

3)、在文件查找 listen_addresses,他的值说明:

a、如果希望只能从本地计算机访问PostgreSQL数据库,就将该项设置为'localhost';

b、如果希望从局域网访问PostgreSQL数据库,就将该项设置为PostgreSQL数据库的局域网IP地址;

c、如果希望从互联网访问PostgreSQL数据库,就将该项设置为PostgreSQL数据库的互联网IP地址;

d、如果希望从任何地方都可以访问PostgreSQL数据库,就将该配置项设置为“*”;

通过ident的描述可以看到上面出现错误(解决psql: 致命错误: 用户 "postgres" Ident 认证失败)的原因是什么了,是因为自己的linux的用户没有和postgresql匹配的用户,才导致出现的错误的,其实这里根据上面的描述有好几种解决方法,由于postgresql数据库会默认生成一个名为postgres的数据库和一个名为postgres的数据库用户,此时,可以同时生成了一个名为postgres的Linux系统用户。但是又不能直接使用root账号切换到postgresql账号,所以需要额外创建一个linux用户用来切换到postgresql账号。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值