postgresql安装 linux PostgreSQL修炼之道:从小工到专家(第2版)

postgresql安装 linux PostgreSQL修炼之道:从小工到专家(第2版)

2.1.1 Red Hat/下的安装方法

在Red Hat、下可使用yum工具来安装,这些操作系统自带的软件库中已有数据库,不过通常版本会低一些。本小节介绍安装官方提供的二进制包的方法。

在图2-1中,我们选择“Red Hat Linux ( /// )”postgresql安装 linux PostgreSQL修炼之道:从小工到专家(第2版),之后会出现一个选择界面,在该界面中选择数据库的版本、平台类型等信息后postgresql安装 linuxpostgresql安装 linux,就会出现具体的安装步骤的提示,如图2-2所示。

在图2-2中,我们选择数据库的版本、操作系统的版本或类型等信息后,就会出现安装方法:首先安装一个安装源,然后再从这个安装源中安装数据库程序。例如,在上面的例子中,安装一个安装源的命令如下。

yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-Red Hat-repo-latest.noarch.rpm

安装完的yum源后,通过“yum ”命令可以看到很多与数据库相关的软件。

然后再从这个安装源中安装数据库程序。通常我们需要安装数据库服务端,命令如下:

yum install postgresql12-server

运行以上命令,数据库的软件就安装完成了。

图2-2 官方yum安装源

上面只是把软件装好了,并未创建数据库实例。创建数据库实例的命令如下:

/usr/pgsql-12/bin/postgresql-12-setup initdb

该数据库创建在“/var/lib/pgsql/12/data”目录下,同时会生成开机自启动的配置,我们可以通过下面的命令允许开机自启动数据库:

systemctl enable postgresql-12

然后用操作系统的服务管理命令启动数据库:

systemctl start postgresql-12

Red Hat7.X/ 7.X是用命令管理服务的,而更早的版本如Red Hat6.X/.X是用命令管理服务的:

service postgresql-12 start

可以用下面的命令查看数据库服务的状态:

systemctl status postgresql-12

可以用命令停止数据库:

systemctl stop postgresql-12

也可以使用下面的命令安装包postgresql安装 linux PostgreSQL修炼之道:从小工到专家(第2版),包中包含了一些插件和工具:

yum install postgresql12-contrib

默认情况下postgresql安装 linux,的数据目录在“/var/lib/pgsql//data”目录下:

[root@pg01 ~]# ls -l /var/lib/pgsql/12/data
total 64
drwx------ 5 postgres postgres    41 Feb 11 13:09 base
-rw------- 1 postgres postgres    30 Feb 11 13:16 current_logfiles
drwx------ 2 postgres postgres  4096 Feb 11 13:09 global
drwx------ 2 postgres postgres    32 Feb 11 13:16 log
drwx------ 2 postgres postgres     6 Feb 11 13:09 pg_commit_ts
drwx------ 2 postgres postgres     6 Feb 11 13:09 pg_dynshmem
-rw------- 1 postgres postgres  4269 Feb 11 13:09 pg_hba.conf
-rw------- 1 postgres postgres  1636 Feb 11 13:09 pg_ident.conf
drwx------ 4 postgres postgres    68 Feb 11 13:21 pg_logical
drwx------ 4 postgres postgres    36 Feb 11 13:09 pg_multixact
drwx------ 2 postgres postgres    18 Feb 11 13:16 pg_notify
drwx------ 2 postgres postgres     6 Feb 11 13:09 pg_replslot
drwx------ 2 postgres postgres     6 Feb 11 13:09 pg_serial
drwx------ 2 postgres postgres     6 Feb 11 13:09 pg_snapshots
drwx------ 2 postgres postgres     6 Feb 11 13:09 pg_stat
drwx------ 2 postgres postgres    25 Feb 11 13:21 pg_stat_tmp
drwx------ 2 postgres postgres    18 Feb 11 13:09 pg_subtrans
drwx------ 2 postgres postgres     6 Feb 11 13:09 pg_tblspc
drwx------ 2 postgres postgres     6 Feb 11 13:09 pg_twophase
-rw------- 1 postgres postgres     3 Feb 11 13:09 PG_VERSION
drwx------ 3 postgres postgres    60 Feb 11 13:09 pg_wal
drwx------ 2 postgres postgres    18 Feb 11 13:09 pg_xact
-rw------- 1 postgres postgres    88 Feb 11 13:09 postgresql.auto.conf
-rw------- 1 postgres postgres 26632 Feb 11 13:09 postgresql.conf
-rw------- 1 postgres postgres    58 Feb 11 13:16 postmaster.opts
-rw------- 1 postgres postgres   103 Feb 11 13:16 postmaster.pid

安装完后我们就可以用psql来连接数据库,首先用su命令切换到用户下:

[root@pg01 ~]# su - postgres
-bash-4.2$ psql
psql (12.1)
Type "help" for help.
postgres=#

然后在psql中输入“q”退出psql。

公告:
1. 本站所有资源来源于用户上传和网络,如有侵权请联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系站长处理!
6. 本站不售卖代码,资源标价只是站长收集整理的辛苦费!如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。
7. 站长QQ号码 2205675299

资源库 - 资源分享下载网 » postgresql安装 linux PostgreSQL修炼之道:从小工到专家(第2版)

常见问题FAQ

关于资源售价和售后服务的说明?
本站所有资源的标价均为本站收集资源的辛苦费,不代表资源本身的价值。软件是高智慧高价值的商品,不可能是白菜价。本站资源标价只是赞助费用,收取的赞助费仅用来维持本站的日常运营!毕竟收集整理资料需要投入云计算资源和站长大量的精力。
代码有没有售后服务和技术支持?
由于代码的运行具有不可预见性,本站不保证代码完整可运行,不提供技术支持和售后服务。 本站原创代码都是站长自己开发的,可以有偿提供技术支持服务。 网站里标明【亲测】的代码都是站长亲测过的,其他的代码由于精力有限,没有一一测试,不能保证代码就一定能够使用,更没有技术支持服务,下载前请自行斟酌。
有没有搭建服务?
由于搭建服务比较费时费力,所以本站除了原创代码外均不提供搭建服务。本站分享代码纯属兴趣爱好,不以盈利为目的,请勿咨询有没有搭建服务,谢谢理解。
链接地址失效了怎么办?
请带上资源链接地址联系客服,工作时间内我们看到后将第一时间回复。
关于解压密码
本站资源一般都没有加密,如果发现需要解压密码的,那么就输入 hao.35dc.com 试试。

发表评论

资源库,由老程序员细心甄别、精心筛选,只为提供优质的源码资源

关于我们 联系我们