Linux下二进制包安装postgresql10.4

因为是二进制包安装,所以我下载的是postgresql-10.4-1-linux-x64-binaries.tar.gz

1.若没有postgres用户组,就先创建postgres用户组

groupadd postgres

useradd –g postgres

passwd postgres

2.解压数据库 tar –xvzf  postgresql-10.4-1-linux-x64-binaries.tar.gz  解压后的文件夹为pgsql

3.创建pgsql数据目录: mkdir /home/postgres/pgsql/data

4.把/home/postgres/pgsql 和/home/postgres/pgsql/data的所有者和所有组改为postgres用户和用户组:

      chown -R postgres:postgres /home/postgres/pgsql

      ll /home/postgres/pgsql              //查看权限更改是否成功,下同

      chown -R postgres:postgres /home/postgres/pgsql/data

      ll /home/postgres/pgsql/data

5.切换到postgres用户来操作数据库,pgsql数据库就以postgres为默认用户,执行: su - postgres 切换。切换之后修改~/.bash_profile将pgsql的bin目录加至环境变量中,方便直接使用pgsql相关命令。

      vim ~/.bash_profile

添加两行:

      export PATH=$PATH:$HOME/bin:/home/postgres/pgsql/bin

      export PGDATA=/home/postgres/pgsql/data

添加并保存后执行  source ~/.bash_profile

6.执行数据库初始化

      /home/postgres/pgsql/bin/initdb -D /home/postgres/pgsql/data

提示“success”字样后,执行

      /home/postgres/pgsql/bin/pg_ctl -D /home/postgres/pgsql/data –l /home/postgres/pgsql/logfile start  则启动数据库。

-l表示指定日志文件位置,这个可以自己指定位置,-D指定数据目录。可以通过ps -ef | grep postgres 查看相关进程。pgsql默认的端口号为5432。

7.远程连接配置

修改data目录下的postgresql.conf文件 把其中的listen_addresses注释去掉  改为listen_addresses=‘*’

修改data目录下的pg_hba.conf文件  在ipv4下加入

host    all         all         0.0.0.0/0         md5

其中0.0.0.0/0表示所有网段ip可访问,改为其他ip地址即表示所修改的网段可以访问,md5为用户认证方式,密码是加密传输的,比较安全。

以上修改需要重启数据库生效。

执行/home/postgres/pgsql/bin/pg_ctl -D /home/postgres/pgsql/data restart  重启。

8.开机启动设置

修改etc/init.d目录下postgres文件,如果是空的,可以把下面代码复制进去,再根据实际情况修改即可。

## EDIT FROM HERE

 

# Installation prefix

prefix=/home/postgres/pgsql

 

# Data directory

PGDATA="/home/postgres/pgsql/data"

 

# Who to run the postmaster as, usually "postgres".  (NOT "root")

PGUSER=postgres

 

# Where to keep a log file

PGLOG="$PGDATA/serverlog"

 

# It's often a good idea to protect the postmaster from being killed by the

# OOM killer (which will tend to preferentially kill the postmaster because

# of the way it accounts for shared memory).  To do that, uncomment these

# three lines:

#PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj

#PG_MASTER_OOM_SCORE_ADJ=-1000

#PG_CHILD_OOM_SCORE_ADJ=0

# Older Linux kernels may not have /proc/self/oom_score_adj, but instead

# /proc/self/oom_adj, which works similarly except for having a different

# range of scores.  For such a system, uncomment these three lines instead:

#PG_OOM_ADJUST_FILE=/proc/self/oom_adj

#PG_MASTER_OOM_SCORE_ADJ=-17

#PG_CHILD_OOM_SCORE_ADJ=0

 

## STOP EDITING HERE

 

# The path that is to be used for the script

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

 

# What to use to start up the postmaster.  (If you want the script to wait

# until the server has started, you could use "pg_ctl start" here.)

DAEMON="$prefix/bin/postmaster"

 

# What to use to shut down the postmaster

PGCTL="$prefix/bin/pg_ctl"

 

 

保存后为所有用户添加改脚本的可执行权限:

chmod a+x /etc/init.d/postgres

最后通过chkconfig命令将该脚本注册为开机启动即可:

chkconfig --add postgres

重启后执行ps -ef|grep postgres可以看到pgsql已经成功启动。

9.远程连接工具

  Navicat for PostgreSQL(收费)、DBeaver(免费)、pgAdmin(免费)

 

注:因为本篇是后来总结的,当初装的时候忘了截图就不重新截图了。。。

转载于:https://www.cnblogs.com/hyomin/p/9373959.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值