Linux下安装PostgresSQL

it2022-05-05  187

1.创建pgsql用户并设置密码: 

useradd postgres passwd postgres

2.准备安装包 postgresql-10.7-1-linux-x64-binaries.tar.gz

3.在 /home/postgres 目录下解压 postgresql-10.7-1-linux-x64-binaries.tar.gz

4.创建pgsql数据目录:

mkdir /home/postgres/pgsql_data

5.给postgres用户授权目录访问权限:

[root@myhadoop postgres]# chown postgres /home/postgres/pgsql_data/

 

6.然后切换到postgres用户来操作数据库

su -postgres

7.初始化数据库:

[postgres@myhadoop ~]$ /home/postgres/pgsql/bin/initdb -D /home/postgres/pgsql_data/

-------------------------------------------------------------------------------- 出现以下信息:

// Success. You can now start the database server using:

    /home/postgres/pgsql/bin/pg_ctl -D /home/postgres/pgsql_data/ -l logfile start /// -------------------------------------------------------------------------------- 8.启动数据库

/home/postgres/pgsql/bin/pg_ctl -D /home/postgres/pgsql_data/ -l logfile start

  关闭数据库

/home/postgres/pgsql/bin/pg_ctl -D /home/postgres/pgsql_data/ -l logfile stop

9.修改data目录下的 postgresql.conf ,增加

listen_addresses = '*'

10.修改data目录下的 pg_hba.conf     86行下面增加

host    all             all             0.0.0.0/0               trust

 

查看端口

netstat -ntulp

进入postgres命令窗口

[postgres@myhadoop ~]$ /home/postgres/pgsql/bin/psql -U postgres -d postgres

配置 postgresql 开机自启动,在 /etc/rc.local 中加上如下启动命令即可

sudo -u postgres -i /home/postgres/pgsql/bin/pg_ctl -D /home/postgres/pgsql_data/ -l logfile start

 


最新回复(0)