postgresql 安装_CentOS7安装使用PostgreSQL数据库
前言
今年个人搭建项目需要使用PostgreSQL12.2数据库,在这里分享下安装过程,有需要的童鞋可以参考下。
PostgreSQL是啥
PostgreSQL是自由的对象-关系型数据库服务器,在灵活的BSD风格许可证下发行。
更多知识,可以搜索:
下面将开始介绍从下载、安装到使用的说明。
1.下载
下载页面:https://www.postgresql.org/ftp/source/
$ wget https://ftp.postgresql.org/pub/source/v12.2/postgresql-12.2.tar.gz
2.操作系统Root用户安装依赖库
# yum install readline-devel# yum install zlib-devel
3.普通用户编译
$ tar zxf postgresql-12.2.tar.gz $ cd postgresql-12.2$ mkdir -p ~/3rd/postgresql-12.2$ ./configure --prefix=/home/testerzhang/3rd/postgresql-12.2$ make$ make install
安装成功,OK
4.环境变量
- 编辑环境变量
$ vim ~/.bash_profileexport PGHOME=$HOME/3rd/postgresql-12.2export PGDATA=$PGHOME/dataexport PATH=$PGHOME/bin:$PATH
- 生效环境变量
$ source ~/.bash_profile
- 验证
$ which psql~/3rd/postgresql-12.2/bin/psql$ which initdb~/3rd/postgresql-12.2/bin/initdb
5.初始化
$ initdbinitdb: error: no data directory specifiedYou must identify the directory where the data for this database systemwill reside. Do this with either the invocation option -D or theenvironment variable PGDATA.
为啥会报错?
如果没有配置环境变量PGDATA,就会报上面这个错,也可以指定[-D, --pgdata=]DATADIR location for this database cluster解决问题。
我们上面已经配置,直接执行就可以了。
$ initdb The files belonging to this database system will be owned by user "testerzhang".This user must also own the server process.The database cluster will be initialized with locale "zh_CN.UTF-8".The default database encoding has accordingly been set to "UTF8".initdb: could not find suitable text search configuration for locale "zh_CN.UTF-8"The default text search configuration will be set to "simple".Data page checksums are disabled.creating directory /home/testerzhang/3rd/postgresql-12.2/data ... okcreating subdirectories ... okselecting dynamic shared memory implementation ... posixselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting default time zone ... Asia/Shanghaicreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... oksyncing data to disk ... okinitdb: warning: enabling "trust" authentication for local connectionsYou can change this by editing pg_hba.conf or using the option -A, or--auth-local and --auth-host, the next time you run initdb.Success. You can now start the database server using: pg_ctl -D /home/testerzhang/3rd/postgresql-12.2/data -l logfile start
看到上面信息代表成功了。
6.访问控制配置文件pg_hba.conf
一般配置文件目录在data目录,具体看下面例子:
$ pwd/home/testerzhang/3rd/postgresql-12.2$ find . -name pg_hba.conf./data/pg_hba.conf
下面开始编辑配置文件
$ vim ./data/pg_hba.conf# "local" is for Unix domain socket connections onlylocal all all trust# IPv4 local connections:#host all all 127.0.0.1/32 trusthost all all 0.0.0.0/0 md5# IPv6 local connections:host all all ::1/128 trust# Allow replication connections from localhost, by a user with the# replication privilege.local replication all trusthost replication all 127.0.0.1/32 trust
这里注释原来的记录加入了:修改为0.0.0.0/0,加密方式改为md5,就表示需要密码访问
host all all 0.0.0.0/0 md5
7.主配置文件postgresql.conf
listen_addresses修改为监听整个网络,请根据实际修改。
$ vim ./data/postgresql.conf#listen_addresses = 'localhost' # what IP address(es) to listen on; # comma-separated list of addresses; # defaults to 'localhost'; use '*' for all # (change requires restart)listen_addresses = '*'
8.启动
-l表示日志文件目录,通常需要指定,所以我们在/usr/local/postgresql根目录下再创建一个log目录用来存放日志文件(注意别忘记赋予可写的权限)。
$ pg_ctl -D /home/testerzhang/3rd/postgresql-12.2/data -l logfile start
9.连接PostgreSQL
创建当前系统普通用户的数据库:
$ createdb testerzhang
连接数据库,默认连接跟系统用户名一样的数据库。
$ psql psql (12.2)Type "help" for help.testerzhang=# testerzhang-# q
如果需要指定连接到某个数据库(test_db),可以用psql -d test_db 。
10.修改用户名的密码
testerzhang=# select * from pg_user; usename | usesysid | usecreatedb | usesuper | userepl | usebypassrls | passwd | valuntil | useconfig ---------+----------+-------------+----------+---------+--------------+----------+----------+----------- testerzhang | 10 | t | t | t | t | ******** | | (1 row)
修改密码
testerzhang=# alter user testerzhang password 'qwerty';ALTER ROLE
11.关闭服务
$ pg_ctl stop
12.常用命令
- 查看所有数据库
l
- 切换数据库: c 参数为数据库名
c database
- 切换用户: c 参数为用户名
c username
- 查看所有表
dt
- d 表名 —— 得到表结构
d table
好了,今天就分享到这里了,你Get到了吗?
我是testerzhang,喜欢本文的童鞋,可以关注我+收藏,不明白的地方也可以评论留言。
postgresql 安装_CentOS7安装使用PostgreSQL数据库相关推荐
- centos php mysql 5.6 安装_centos7安装nginx、php5.5、mysql5.6
一.nginx 1.安装 yum install nginx 2.启动 systemctl start nginx 关闭:systemctl stop nginx 重启:systemctl resta ...
- centos7 mysql 安装_CentOS7安装MySQL8.0图文教程(相对最齐全)
登录主机,然后进行下载 第一步:在mysql官网下载源文件 第二步:Select Operating System: 选择 Red Hat ,CentOS 是基于红帽的,Select OS Versi ...
- mysql8.0 tar安装_CentOS7安装MySQL8.0 tar包
CentOS7安装MySQL8.0 tar包 一.卸载 1. 查看有没有安装mysql rpm -qa | grep mysql 删除 #rpm -e --nodeps mysql-libs-5.1. ...
- console线驱动安装_centos7安装docker
docker是一个容器技术平台,可以方便的部署.构建应用程序,工作中使用docker安装部署个程序简直不要太爽.本文只介绍下docker的安装,其他技术内容欢迎关注我,喜欢的点个赞. 1.检查内核版本 ...
- centos jupyter 安装_centos7安装 jupyter
Jupyter Notebook(此前被称为 IPython notebook)是一个交互式笔记本,支持运行 40 多种编程语言. Jupyter Notebook 的本质是一个 Web 应用程序,便 ...
- centos7 docker安装_Centos7 安装 Docker
Centos7 安装 Docker 1.卸载旧版本 sudo yum remove docker docker-client docker-client-latest docker-common do ...
- zookeeper安装_Centos7安装配置Zookeeper
前言: 在小企业或者一些小项目中,当网站流量很小时,只需一个应用,便能将所有功能都部署在一起,以减少部署节点和成本.但当访问量逐渐增大,单一应用增加机器带来的加速度越来越小,将应用拆成互不相干的几个应 ...
- centos7 安装redmin3.3.0+postgresql数据库
一.前言 Redmine是用Ruby开发的基于web的项目管理软件,是用ROR框架开发的一套跨平台项目管理系统,据说是源于Basecamp的ror版而来,支持多种数据库,有不少自己独特的功能,例如提供 ...
- pg安装部署linux_Linux下postgresql数据库部署与配置
1.检查postgresql是否已经安装:rpm -qa | grep postgres 2.检查PostgreSQL 安装位置:rpm -qal | grep postgres 3.卸载Postgr ...
最新文章
- JS根据两点的经纬度坐标得到驾车行驶距离
- 《iOS 6高级开发手册(第4版)》——导读
- 安德鲁斯Launcher得到的装在手机的应用程序列表
- ML.NET 示例:将ML.NET模型导出到ONNX
- win7精简_低配电脑的福音:这款小众系统10GB+极限精简+不卡顿,比Win7还快!
- 用C#实现软件自动更新
- 新一季“十大最堵互联网公司”出炉:360百度腾讯跻身三甲
- linux之使用grep搜索文本
- C++控制台RPG游戏具体实现思路: 任务系统
- 隐马尔可夫模型(一)概念
- 那些实用的 Chrome 扩展神器(二)
- 微信小程序详解 php,微信小程序canvas基础详解
- 自动调节式防涝井盖设计
- 如何评价ERP实施绩效 (zt)
- 华为HDG苏州站:重体验,创新品 一切从开发者的角度出发
- android 网页词典,android 有道词典查询单词(webview版)
- 如何打造 茄子快传 这样一款文件传输应用
- 如何使用Omnifocus做时间管理 4 多项目管理
- java class getfield_java.lang.Class.getField()方法实例
- png 矢量图 RGBA 转 RGB后变黑问题解决
热门文章
- 7、MySQL数据类型的选择
- 【PAT乙级】1079 延迟的回文数 (20 分)
- 小米6自动重启android,小米6充电重启怎么办 小米6充电自动重启解决方法
- 网络盒子android系统版本怎样刷机,咪咕盒子MG100强制刷机rom固件安卓系统包_刷机教程...
- 四川c语言二级成绩查询,四川省计算机等级考试二级C语言考试分析(hcy__ ).ppt
- pythontkinter在一块区域中绘图_用Python中的tkinter模块作图(续)
- 【PAT】A1079 Total Sales of Supply Chain
- Keras保存和载入训练好的模型和参数
- apt-get update 出现E: Could not get lock /var/lib/apt/lists/lock问题的解决
- Java设计模式-Proxy代理模式