网站首页 > 教程分享 正文
来源: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
猜你喜欢
- 2024-10-25 PostgreSQL之慢SQL语句(如何解决慢sql)
- 2024-10-25 Postgresql语法(POSTGRESQL语法)
- 2024-10-25 python开发-操作postgresql数据库
- 2024-10-25 新手如何快速搭建多套PostgreSQL集群
- 2024-10-25 Postgresql基础操作实战(postgresql基础操作实战视频)
- 2024-10-25 一次近乎完美的PostgreSQL版本大升级实践
- 2024-10-25 数据库大师成长日记:您所不知道的PostgreSQL,值得收藏
- 2024-10-25 【PostgreSQL】AUTO_EXPLAIN - 慢速查询的日志执行计划
- 2024-10-25 postgresql安装及使用(postgresql安装使用)
- 2024-10-25 PostgreSQL系列(三):字符串类型操作(一)
你 发表评论:
欢迎- 最近发表
-
- IT之家学院:使用PIN或密码审批管理员权限
- Yarn 安装的时候提示错误 error:0308010C:digital envelope routines
- Windows常用的一些CMD运行命令(windows常见的命令)
- 电脑忘记开机密码10秒解决(戴尔电脑忘记开机密码10秒解决)
- 如何下载Windows 10聚焦提供的锁屏壁纸
- Windows CMD 命令大全:简单粗暴收藏!
- 系统小技巧:解决CHKDSK只读模式问题
- Windows的cmd都有哪些奇技淫巧?这22个CMD命令记得收藏起来!
- windows错误代码0x80072EE2?win10系统更新错误问题的处理方法
- Windows 10技术预览版快捷键方式汇总
- 标签列表
-
- css导航条 (66)
- sqlinsert (63)
- js提交表单 (60)
- param (62)
- parentelement (65)
- jquery分享 (62)
- check约束 (64)
- curl_init (68)
- sql if语句 (69)
- import (66)
- chmod文件夹 (71)
- clearinterval (71)
- pythonrange (62)
- 数组长度 (61)
- javafx (59)
- 全局消息钩子 (64)
- sort排序 (62)
- jdbc (69)
- php网页源码 (59)
- assert h (69)
- httpclientjar (60)
- postgresql conf (59)
- winform开发 (59)
- mysql数字类型 (71)
- drawimage (61)
本文暂时没有评论,来添加一个吧(●'◡'●)