在linux环境下安装postgresql 9.4
发布日期:2021-06-30 11:47:21 浏览次数:2 分类:技术文章

本文共 1827 字,大约阅读时间需要 6 分钟。

环境说明

系统:centos 6.4 64位

软件:postgresql 9.4.1

软件下载

cd /usr/local/src/

wget 

安装依赖包

yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++   openssl-devel cmake

安装postgresql

tar xf postgresql-9.4.1.tar.gz

cd postgresql-9.4.1

./configure --prefix=/usr/local/pgsql --with-perl --with-python --with-libxml --with-libxslt

gamke

gamke install

安装PG插件

cd /usr/local/src/postgresql-9.4.1/contrib

gmake

gmake install

加载动态库

echo "/usr/local/pgsql/lib" >> /etc/ld.so.conf.d/pgsql.conf

ldconfig

初始化数据库

创建用户postgres

useradd postgres

echo "postgres"|passwd --stdin postgres

创建PG数据目录

mkdir -p /data/pg/data

chown -R postgres:postgres /data/pg

/usr/local/pgsql/bin/initdb --no-locale -U postgres -E utf8 -D /data/pg/data -W

(在初始化的时候,看提示添加超级用户的密码)

配置运行环境变量(方便管理

切换到root

vim /etc/profile

添加以下代码:

PGDATA=/data/pg/data

PGHOST=127.0.0.1

PGDATABASE=postgres

PGUSER=postgres

PGPORT=5432

PATH=/usr/local/pgsql/bin:$PATH

export PATH

export PGDATA PGHOST PGDATABASE PGUSER PGPORT

执行生效

source /etc/profile

postgresql服务管理

启动:

pg_ctl start -D /data/pg/data

重启:

pg_ctl restart -D /data/pg/data

停止:

pg_ctl stop -D /data/pg/data

强制重启:

pg_ctl restart -D /data/pg/data -m f

强制停止:

pg_ctl stop -D /data/pg/data -m f

-m f 指定快速关闭

加载配置:

pg_ctl reload -D  /data/pg/data

显示服务状态:

pg_ctl status -D  /data/pg/data

连接数据库

psql -h 127.0.0.1 -U postgres -p 5432 -d postgres -W

-d 指定数据库 ,-W 输入密码 , -U 指定用户,-p 指定端口,-h 指定IP

复制PostgreSQL执行脚本

cp /usr/local/src/postgresql-9.4.1/contrib/start-scripts/linux /etc/init.d/postgresql

chmod +x /etc/init.d/postgresql

修改/etc/init.d/postgresql  

把PGDATA改成PGDATA=/data/pg/data

加入开机启动

chkconfig postgresql on

管理PG服务时也可以直接用上面启动脚本

启动:service postgresql start

停止:service postgresql stop

重启:service postgresql restart

加载:service postgresql reload

状态:serivce postgresql status

转载地址:https://jackiehao.blog.csdn.net/article/details/100563526 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:python bottle框架环境安装
下一篇:PS命令定时执行自动下载 Windows 10 聚焦壁纸

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2024年04月25日 09时21分51秒