安装postgresql11.5
root身份安装
创建用户 编译安装成功后,接下来要做的就是创建一个普通用户,因为默认超级用户(root)不能启动postgresql,所以需要创建一个普通用户来启动数据库,执行以下命令创建用户: [root@localhost build_dir]# groupadd postgres
[root@localhost build_dir]# useradd -g postgres postgres
[root@localhost build_dir]# passwd postgres 接下来设置权限,将pg的数据目录全部赋给postgres用户,执行以下命令: [root@localhost build_dir]# chown -R postgres:postgres /usr/local/pgsql 创建目录 [root@localhost build_dir]# mkdir -p /mnt/db1/pgdata/pgsql /mnt/db1/pgdata/pgtbs /mnt/db1/archivelog /backups
[root@localhost build_dir]# chmod -R /mnt/db1
[root@localhost build_dir]# chown -R postgres:postgres /mnt/db1 设置环境变量 [root@localhost build_dir]# vi /home/postgres/.bash_profile PATH=$PATH:$HOME/.local/bin:$HOME/bin export PATH export PGPORT=
export PGHOME=/usr/local/pgsql
export PGDATA=/mnt/db1/pgdata/pgsql
export PATH=$PGHOME/bin:$PATH
export MANPATH=$PGHOME/share/man:$MANPATH
export LANG=en_US.UTF-
export DATE='date +"%Y%m%d%H%M"'
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
export PGHOST=$PGDATA
export PGUSER=postgres
export PGDATABASE=postgres PATH=$PATH:$HOME/.local/bin:$HOME/bin:$PGHOME/bin
export PATH 执行如下命令使其生效: [root@localhost build_dir]# source /home/postgres/.bash_profile
准备
由于centos自带的版本不够高,直接安装postgresql会报错,所以先给llvm和clang升级
# wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# yum localinstall epel-release-latest-7.noarch.rpm
# yum install llvm5.0 llvm5.0-devel clang yum install -y
gcc gcc-c++
openssl openssl-devel
readline readline-devel
zlib zlib-devel
llvm5. llvm5.-devel
libxml2-devel
libxslt-devel
libicu-devel python-devel
tcl-devel
systemd-devel
openldap-devel
pam-devel clang
perl-ExtUtils-Embed
epel-release 实际执行:
yum install -y gcc gcc-c++ epel-release llvm5.0 llvm5.0-devel clang libicu-devel perl-ExtUtils-Embed readline readline-devel zlib zlib-devel openssl openssl-devel pam-devel libxml2-devel libxslt-devel openldap-devel systemd-devel tcl-devel python-devel
但是公司centos6.3电脑上:无法安装systemd-devel,llvm5.0 ,llvm5.0-devel
configure
# cd build_dir/
vim ../src/Makefile.global.in
修改以下行:
COMPILE.c.bc = $(CLANG) -Wno-ignored-attributes $(BITCODE_CFLAGS) $(CPPFLAGS) -flto=thin -emit-llvm -c
修改为:
COMPILE.c.bc = $(CLANG) -Wno-ignored-attributes $(BITCODE_CFLAGS) $(CPPFLAGS) -emit-llvm -c -- --prefix 指定默认安装路径
[root@localhost build_dir]# ../configure
--prefix=/usr/local/pgsql
--enable-nls
--with-perl
--with-python
--with-tcl
--with-gssapi
--with-llvm LLVM_CONFIG='/usr/lib64/llvm5.0/bin/llvm-config'
--with-icu
--with-openssl
--with-pam
--with-ldap
--with-systemd
--with-libxml
--with-libxslt #configure 命令完成后,会发现创建了 config.status 配置文件
# 实际执行:
./configure --prefix=/home/cdrom/work/postgresql11_5432 --enable-nls --with-perl --with-python --with-tcl --with-gssapi --with-llvm LLVM_CONFIG='/usr/lib64/llvm5.0/bin/llvm-config' --with-icu --with-openssl --with-pam --with-ldap --with-systemd --with-libxml --with-libxslt
make
make install
初始化数据库 切换用户
[root@localhost build_dir]# su - postgres
初始化数据库
[postgres@localhost ~]$ initdb -D $PGDATA -U postgres --locale=en_US.UTF8 -E UTF8 修改监听地址 将listen_addresses的值设置成*,使其监听整个网络,端口号默认是5432,也可以自己设置。 [postgres@localhost ~]$ vim /mnt/db1/pgdata/pgsql/postgresql.conf
修改内容:
listen_addresses = '*'
unix_socket_directories = '.'
port = 修改客户端认证方式 [postgres@localhost ~]$ vim /mnt/db1/pgdata/pgsql/pg_hba.conf
添加内容:
host all all 0.0.0.0/ md5 # 其他用户登陆 设置防火墙规则 #切换回root用户
[postgres@localhost ~]$ exit
[root@localhost build_dir]# firewall-cmd --zone=public --add-port=/tcp --permanent
[root@localhost build_dir]# firewall-cmd --reload 启动数据库 [root@localhost build_dir]# su - postgres
启动
[postgres@localhost ~]$ pg_ctl -D /mnt/db1/pgdata/pgsql -l /mnt/db1/archivelog/pgsql.log start
停止
[root@localhost postgres]# pg_ctl -D /mnt/db1/pgdata/pgsql/ -s -m fast stop 连接测试 [postgres@localhost ~]$ psql
查询所有用户
postgres=# select * from pg_user;
postgres=# select * from pg_roles;
查询权限
postgres=# select * from information_schema.table_privileges where grantee='cc';
查看有哪些数据库
postgres=# \l
相当与mysql的show databases;
postgres=# select datname from pg_database;
相当于mysql的show tables, public 是默认的schema的名字
postgres=# SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';
相当与mysql的describe table_name, 'table_name'是要查询的表的名字
postgres=# SELECT column_name FROM information_schema.columns WHERE table_name ='table_name';
退出
postgres=# \q psql 是 PostgreSQL 的客户端程序,要连接 PostgreSQL 数据库,我们需要指定以下内容: -d or --dbname 数据库名
-h or --host 主机名
-p or --port 端口号,默认5432 端口
-U or --username 用户名
[postgres@localhost ~]$ psql -h localhost -p -U postgres 设置postgres用户密码 [postgres@localhost ~]$ psql
postgres=# ALTER USER postgres WITH encrypted PASSWORD 'new password';
postgres=# \q
[postgres@localhost ~]$ psql -h localhost -p -U postgres 设置开机自启动 设置启动配置 vim /usr/lib/systemd/system/postgresql-.service
添加内容:
[Unit]
Description=PostgreSQL database server
Documentation=https://www.postgresql.org/docs/11/static/
After=syslog.target
After=network.target [Service]
Type=notify User=postgres
Group=postgres # Location of database directory
Environment=PGDATA=/mnt/db1/pgdata/pgsql/ # Where to send early-startup messages from the server (before the logging
# options of postgresql.conf take effect)
# This is normally controlled by the global default set by systemd
# StandardOutput=syslog # Disable OOM kill on the postmaster
OOMScoreAdjust=- Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
Environment=PG_OOM_ADJUST_VALUE= # ExecStartPre=/usr/pgsql-/bin/postgresql--check-db-dir ${PGDATA}
ExecStart=/usr/local/pgsql/bin/postmaster -D ${PGDATA}
ExecReload=/bin/kill -HUP $MAINPID
# ExecStart=/usr/local/pgsql9./bin/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t
# ExecStop=/usr/local/pgsql9./bin/pg_ctl stop -D ${PGDATA} -s -m fast
# ExecReload=/usr/local/pgsql9./bin/pg_ctl reload -D ${PGDATA} -s
KillMode=mixed
KillSignal=SIGINT # Do not set any timeout value, so that systemd will not kill postmaster
# during crash recovery.
TimeoutSec= [Install]
WantedBy=multi-user.target 添加可执行权限 [root@localhost postgres]# chmod /usr/lib/systemd/system/postgresql-.service 设置开机自启动 自动启动
[root@localhost postgres]# systemctl enable postgresql-.service
启动
[root@localhost postgres]# systemctl start postgresql-.service
停止某服务
[root@localhost postgres]# systemctl stop postgresql-.service
不自动启动
[root@localhost postgres]# systemctl disable postgresql-.service
检查服务状态(服务详细信息)
systemctl status postgresql-.service
检查服务状态(仅显示是否Active)
systemctl is-active postgresql-.service
显示所有已启动的服务
systemctl list-units --type=service
################################################################
centos6.3上安装如下:
systemd-devel,llvm5. ,llvm5.-devel,没有安装上。
./configure --prefix=/home/postgres/postgres11_5434 --enable-nls --with-perl --with-python --with-tcl --with-gssapi --with-openssl --with-pam --with-ldap --with-libxml --with-libxslt
同时在make的时候会出错,需要将postgresql-11.5/src/test/isolation目录下面的specs目录给换个名称,但是目前还不知道有什么影响
make -j4 make install
安装postgresql11.5的更多相关文章
- Windows安装PostgreSQL11.1
Windows安装PostgreSQL11.1 安装过程如下: 1.下载安装包postgresql-11.1-1-windows-x64.exe 2.点击下一步 3.选择安装位置,默认路径C:\Pro ...
- Centos75 安装 postgresql11
切换到root账户, #安装yum 源 yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_6 ...
- CentOs7.5安装PostgreSQL11
前言 本章介绍在CentOs上安装一个PostgreSQL数据库 下一篇可能是安装 Redis 本篇使用的服务器是已经安装过Python/Nginx等常用软件的环境,因此在安装过程中可能会遇到按照本章 ...
- centos7 安装postgresql11
1 进入postresql官网下载页面,提示了centos相关下载安装等信息. https://www.postgresql.org/download/linux/redhat/ image.pn ...
- 离线安装PostgreSQL11.6
因为客户最近有一台CentOS7的虚拟机,但是没有联网,需要安装离线安装PostgreSQL 1.首先去官网下载离线安装包 https://www.postgresql.org/download/ 说 ...
- CentOS7安装postgreSQL11
1.添加PostgreSQL Yum存储库 sudo yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel- ...
- CentOS7(64) yum安装、配置PostgreSQL 11
一.安装postgresql11 1.Install the repository RPM: 添加RPM yum install https://download.postgresql.org/pub ...
- 在CentOS7上部署PostgreSQL11数据库系统
在数据库上的选择,也是基于了稳定性为前提.其实选择的范围并不是太大,基本可以选择的范围也就是SQLServer.MySQL.PostgreSQL这三种.SQL Server是微软的商业数据库,无论是性 ...
- Centos7 源码安装PostgreSQL Citus集群 (转载)
citus的分布式集群目前在苏宁大规模应用,苏宁陈华军也做了很多技术分享和博客介绍.目前所有的教程都是rpm和pg一起安装,个人不喜欢,毕竟citus定位是个插件,我想在我已安装的pg上源码装一个ci ...
随机推荐
- HashMap 什么时候进行扩容呢
HashMap扩容: 当HashMap中的元素越来越多的时候,碰撞的几率也就越来越高(因为数组的长度是固定的),所以为了提高查询的效率,就要对HashMap的数组进行扩容,数组扩容这个操作也会出现在A ...
- VS2010-MFC(常用控件:列表框控件ListBox)
转自:http://www.jizhuomi.com/software/186.html 列表框控件简介 列表框给出了一个选项清单,允许用户从中进行单项或多项选择,被选中的项会高亮显示.列表框可分为单 ...
- VS2010-MFC(常用控件:编辑框Edit Control)
转自:http://www.jizhuomi.com/software/181.html 编辑框(Edit Control)是一种很常用的控件,我们可以在编辑框中输入并编辑文本.在前面加法计算器的例子 ...
- 141 x的平方根
原题网址:http://www.lintcode.com/zh-cn/problem/sqrtx/ 实现 int sqrt(int x) 函数,计算并返回 x 的平方根. 您在真实的面试中是否遇到过这 ...
- System.Drawing.Image.cs
ylbtech-System.Drawing.Image.cs 1.程序集 System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyTok ...
- SPSS Modeler数据挖掘:回归分析
SPSS Modeler数据挖掘:回归分析 1 模型定义 回归分析法是最基本的数据分析方法,回归预测就是利用回归分析方法,根据一个或一组自变量的变动情况预测与其相关的某随机变量的未来值. 回归分析是研 ...
- mybatis中处理结果集映射
单行结果集映射: 接口中方法返回值定义为Map类型,sql语句的resultType属性设置为map即可.这种情况默认把列名作为key,列中的值作为value. 也就是说用map<Strirng ...
- telnet- Linux必学的60个命令
1.作用 telnet表示开启终端机阶段作业,并登入远端主机.telnet是一个Linux命令,同时也是一个协议(远程登陆协议). 2.格式 telnet [-8acdEfFKLrx][-b][-e] ...
- [NOIP2019模拟赛]数数(gcd)
题目大意: 求l~r中有多少数与x互质,带单点修改 分析: 两个30的部分分很好打: ·n<=1000暴力O(nq)就好了 ·$a_i<=100$用树状数组维护每个x的前缀和就好了 100 ...
- Ubuntu下安装和配置Apache2,小编觉得挺不错的,现在就分享给大家
本篇文章主要介绍了详解Ubuntu下安装和配置Apache2,小编觉得挺不错的,现在就分享给大家,也给大家做个参考.有兴趣的朋友可以了解一下.(http://xz.8682222.com) 在Ubun ...