ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

postgresql单机多开

2022-01-25 18:35:04  阅读:257  来源: 互联网

标签:25 01 postgresql postgres 单机 18 多开 ------. drwx


单机多开也叫多实例:

su postgres -c "/usr/pgsql-12/bin/pg_ctl -D 数据目录 start"   #还可以stop ,reload

单机多开 postgresql ,只需要创建好不同的目录,给目录分配好权限,修改端口避免冲突,然后分别执行上面的命令启动即可。

下面我们来演示一下:

安装过程可以参考之前的文章:

[root@localhost 14]# ll
总用量 8
drwx------.  2 postgres postgres    6 11月 10 23:46 backups
drwx------. 20 postgres postgres 4096 1月  25 18:01 data
-rw-------.  1 postgres postgres  990 1月  25 18:01 initdb.log
[root@localhost 14]# cp -rf data data1
[root@localhost 14]# chown -R postgres:postgres data1
[root@localhost 14]# ll
总用量 12
drwx------.  2 postgres postgres    6 11月 10 23:46 backups
drwx------. 20 postgres postgres 4096 1月  25 18:01 data
drwx------. 20 postgres postgres 4096 1月  25 18:01 data1
-rw-------.  1 postgres postgres  990 1月  25 18:01 initdb.log
[root@localhost 14]# cd data1/
[root@localhost data1]# ll
总用量 68
drwx------. 5 postgres postgres    41 1月  25 18:01 base
-rw-------. 1 postgres postgres    30 1月  25 18:01 current_logfiles
drwx------. 2 postgres postgres  4096 1月  25 18:01 global
drwx------. 2 postgres postgres    32 1月  25 18:01 log
drwx------. 2 postgres postgres     6 1月  25 18:01 pg_commit_ts
drwx------. 2 postgres postgres     6 1月  25 18:01 pg_dynshmem
-rw-------. 1 postgres postgres  4577 1月  25 18:01 pg_hba.conf
-rw-------. 1 postgres postgres  1636 1月  25 18:01 pg_ident.conf
drwx------. 4 postgres postgres    68 1月  25 18:01 pg_logical
drwx------. 4 postgres postgres    36 1月  25 18:01 pg_multixact
drwx------. 2 postgres postgres     6 1月  25 18:01 pg_notify
drwx------. 2 postgres postgres     6 1月  25 18:01 pg_replslot
drwx------. 2 postgres postgres     6 1月  25 18:01 pg_serial
drwx------. 2 postgres postgres     6 1月  25 18:01 pg_snapshots
drwx------. 2 postgres postgres     6 1月  25 18:01 pg_stat
drwx------. 2 postgres postgres    25 1月  25 18:01 pg_stat_tmp
drwx------. 2 postgres postgres    18 1月  25 18:01 pg_subtrans
drwx------. 2 postgres postgres     6 1月  25 18:01 pg_tblspc
drwx------. 2 postgres postgres     6 1月  25 18:01 pg_twophase
-rw-------. 1 postgres postgres     3 1月  25 18:01 PG_VERSION
drwx------. 3 postgres postgres    60 1月  25 18:01 pg_wal
drwx------. 2 postgres postgres    18 1月  25 18:01 pg_xact
-rw-------. 1 postgres postgres    88 1月  25 18:01 postgresql.auto.conf
-rw-------. 1 postgres postgres 28769 1月  25 18:01 postgresql.conf
-rw-------. 1 postgres postgres    58 1月  25 18:01 postmaster.opts
-rw-------. 1 postgres postgres   103 1月  25 18:01 postmaster.pid

这里注意要将postmaster.pid删除掉,不然启动不了,会报文件已经被锁定的错误,因为这个文件是data里面拷贝的所以是刚开始第一次启动postgresql所生成的,通过上面的命令再次启动的话就会生成同一个文件里面的值不一样而已

修改data1里的postgresql.conf文件

只修改端口号即可

port = 15432 

然后执行下面的命令启动该实例

su postgres -c "/usr/pgsql-14/bin/pg_ctl -D ./data1 start" 

结果:

[root@localhost 14]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      941/sshd            
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      1608/postmaster     
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1161/master         
tcp        0      0 127.0.0.1:15432         0.0.0.0:*               LISTEN      1668/postgres       
tcp6       0      0 :::22                   :::*                    LISTEN      941/sshd            
tcp6       0      0 ::1:5432                :::*                    LISTEN      1608/postmaster     
tcp6       0      0 ::1:25                  :::*                    LISTEN      1161/master         
tcp6       0      0 ::1:15432               :::*                    LISTEN      1668/postgres       
[root@localhost 14]# 

两个实例已经都启动了,一个端口号是5432,第二个是15432

可以通过以下命令分别登陆:

登陆第一个实例:

su - postgres
psql -p 5432

登陆第二个实例:

su - postgres
psql -p 15432

两个实例互不影响

 

标签:25,01,postgresql,postgres,单机,18,多开,------.,drwx
来源: https://www.cnblogs.com/ezgod/p/15844155.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有