网站首页 > 教程文章 正文
来源:https://mp.weixin.qq.com/s/Dmw8jO3KO-y14byeDMLjZg
官方文档
二进制安装和启动:
https://www.postgresql.org/download/linux/redhat/
源码安装和启动:
https://www.postgresql.org/docs/11/install-procedure.html
https://www.postgresql.org/docs/11/creating-cluster.html
https://www.postgresql.org/docs/11/server-start.html
https://www.postgresql.org/docs/current/kernel-resources.html
两种方法
1、二进制安装(linux是rpm包,windows是exe安装文件)
2、源码安装,推荐安装方式
二进制安装
示例:centos7_64平台,数据库postgresql11,使用yum安装
不使用yum的话可以直接使用rpm包安装,rpm包下载地址https://yum.postgresql.org/rpmchart.php
1、安装RPM的yum源,其实就是下载一个postgresql的yum源pgdg-redhat-all.repo文件到/etc/yum.repos.d目录下,有了这个yum源后,就可以直接yum install postgresql11安装postgresql数据库了
yum install
https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
2、安装客户端,先执行search看有哪些PostgreSQL client可供安装
yum search 'PostgreSQL client'
yum install postgresql11
3、安装服务端,先执行search看有哪些PostgreSQL server可供安装,以下步骤安装好后,会自动创建用户postgres,自动创建目录/usr/pgsql-11
yum search 'PostgreSQL server'
yum install postgresql11-server
4、初始化数据库并启用开机自动启动
/usr/pgsql-11/bin/postgresql-11-setup initdb
systemctl enable postgresql-11
systemctl start postgresql-11
5、查看postgresql的进程
[root@zabbixtest2 ~]# ps -ef|grep postgres
postgres 1527 1 0 01:13 ? 00:00:00 /usr/pgsql-11/bin/postmaster -D /var/lib/pgsql/11/data/
6、连接postgresql数据库
su - postgres
psql -l
psql -d postgres
源码安装
1、建立postgresql用户、内核资源的配置,主要涉及/etc/security/limits.conf、/etc/sysctl.conf文件,类似oracle也需要配置这两个文件
2、解压tar包,进入解压目录,使用root用户执行如下,最后的make install命令把软件安装到/postgresql/pgsql目录
./configure --prefix=/postgresql/pgsql
make
make install
3、把软件安装目录/postgresql/pgsql授权宿主用户为postgresql
4、编辑postgresql用户的.bash_profile文件,PATH= /postgresql/pgsql/bin :$PATH、LD_LIBRARY_PATH= /postgresql/pgsql /lib
5、初始化数据库,后面两条命令任意一条都可以
su - postgresql
initdb -D /postgresql/pgsql/data
pg_ctl -D /postgresql/pgsq l/data initdb
6、启动postgresql程序,下面任意一个都可以,官方文档建议使用pg_ctl
postgres -D /postgresql/pgsql/data >logfile 2>&1 &
pg_ctl start -D /postgresql/pgsql/data -l logfile
7、查看postgresql的进程
[root@zabbixtest1 ~]# ps -ef|grep postgres
postgre+ 803 1 0 07:10 pts/0 00:00:00 /postgresql/pgsql/bin/postgres -D /postgresql/pgsql/data
8、连接postgresql数据库,指定连接postgres库
psql -l
psql -d postgres
备注 :psql命令不加端口和不加数据库名,表示默认进入端口为5432并且数据库名和初始数据库initdb时的用户名一样的数据库,比如初始数据库initdb时的用户名为A,则默认进入A库。postgresql的默认端口是5432,默认数据库是postgres、template0、template1
如果此时端口不是5432,则会报错psql: FATAL: role "A" does not exist
因为安装用户"A"对应的实例端口为其他,端口5432数据库的Owner不是"A"
如果此时没有"A"库,则会报错psql: FATAL: database "A" does not exist
因为安装用户"A",默认进入"A"库,而"A"库是不存在的
9、创建一个名为test的数据库
createdb test
10、查看数据库状态
pg_ctl status -D /postgresql/pgsql/data
11、关闭数据库
pg_ctl stop -D /postgresql/pgsql/data
官方文档Short Version简要步骤
./configure
make
su
make install
adduser postgres
mkdir /usr/local/pgsql/data
chown postgres /usr/local/pgsql/data
su - postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &
/usr/local/pgsql/bin/createdb test
/usr/local/pgsql/bin/psql test
猜你喜欢
- 2025-01-10 AI编程之手把手教你在CentOS安装Postgresql的Vector向量数据库
- 2025-01-10 postgresql在centos安装
- 2025-01-10 PostgreSQL技术内幕13:PostgreSQL通讯协议
- 2025-01-10 等保2.0测评:PostgreSQL数据库
- 2025-01-10 PostgreSQL技术内幕10:PostgreSQL事务原理解析-日志模块介绍
- 2025-01-10 基于patroni+etcd打造可自动故障转移的PostgreSQL集群
- 2025-01-10 新手如何快速搭建多套PostgreSQL集群
- 2025-01-10 PostgreSQL是不是你的下一个JSON数据库?
- 2025-01-10 轻松入门PostgreSQL:安装和设置数据库的完整指南!
- 2025-01-10 PostgreSQL、MySQL 数据库被入侵究竟有多么普遍?有人做了一项实验
- 05-08云虚拟电脑与操作云电脑:相同还是不同?
- 05-08【三.丰.云】免费虚拟主机和免费云服务器,真的不错
- 05-08三丰云免费虚拟主机和云服务器评测
- 05-08阿贝云:免费的虚拟主机和云服务器,让我爱上云计算
- 05-08云服务器与虚拟主机的区别解析(云服务器与虚拟主机的区别解析图)
- 05-08(可以搭建游戏无盘)推荐一个免费云服务器,免费虚拟主机
- 05-08【阿贝云】免费云主机,免费虚拟主机
- 05-08免费云服务器和虚拟主机(免费云服务器和虚拟主机的区别)
- 最近发表
- 标签列表
-
- location.href (44)
- document.ready (36)
- git checkout -b (34)
- 跃点数 (35)
- 阿里云镜像地址 (33)
- qt qmessagebox (36)
- md5 sha1 (32)
- mybatis plus page (35)
- semaphore 使用详解 (32)
- update from 语句 (32)
- vue @scroll (38)
- 堆栈区别 (33)
- 在线子域名爆破 (32)
- 什么是容器 (33)
- sha1 md5 (33)
- navicat导出数据 (34)
- 阿里云acp考试 (33)
- 阿里云 nacos (34)
- redhat官网下载镜像 (36)
- srs服务器 (33)
- pico开发者 (33)
- https的端口号 (34)
- vscode更改主题 (35)
- 阿里云资源池 (34)
- os.path.join (33)