centos7 linux安装 postgresql 10.1

官网也有安装的方式,我习惯了编译安装。 总结编译安装的方式:

第一种 yum安装:

每一行代表一行命令

yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm
yum install postgresql10
yum install postgresql10-server
/usr/pgsql-10/bin/postgresql-10-setup initdb
systemctl enable postgresql-10
systemctl start postgresql-10

可以参考pgsql的官网 都给予了安装方式

https://www.postgresql.org/download/linux/redhat/

  1. 登录命令: psql -U postgres 会进入postgres用户的控制台

  2. 执行:psql -U postgres 或者   sudo -u postgres psql 可以进入数据库

  3. \l 查看有哪些数据库

  4. \c postgresql 选择postgresql 这个数据库,会提示进入连接

创建用户:create user username with login password 'password';
修改登录PostgreSQL密码  ALTER USER postgres WITH PASSWORD 'postgres';

允许远程访问配置:

修改 PostgreSQL 配置文件 postgresql.conf
我的配置文件在 /var/lib/pgsql/10/data/postgresql.conf
把 listen_addresses = 'localhost'
改为 listen_addresses = '*'
重启 即可

使用远程工具连接时如果无法连接

vim /var/lib/pgsql/10/data/pg_hba.conf

则添加到86行左右

#自行添加 乔永刚
host all all 0.0.0.0/0 md5

进入pgsql

先切换到postgresql用户

su postgresql 

psql -U postgres

-----------------------------------------------------------------------------------------------------------------------------------------------

第二种 编译安装

第一步:

打开pgsql的官网下载tar包

地址:

https://www.postgresql.org/ftp/source/v10.1/

解压完毕

第二步 :

./configure

此时可能会报错:

configure: error: readline library not found

如果报错则执行:

yum -y install -y readline-devel

参考地址:https://www.linuxidc.com/Linux/2012-02/53982.htm

第三步:

make && make install

最终提示:


make[1]: Leaving directory `/root/postgresql-10.1/src'
make -C config install
make[1]: Entering directory `/root/postgresql-10.1/config'
/usr/bin/mkdir -p '/usr/local/pgsql/lib/pgxs/config'
/usr/bin/install -c -m 755 ./install-sh '/usr/local/pgsql/lib/pgxs/config/install-sh'
/usr/bin/install -c -m 755 ./missing '/usr/local/pgsql/lib/pgxs/config/missing'
make[1]: Leaving directory `/root/postgresql-10.1/config'
PostgreSQL installation complete.

安装成功

猜你喜欢

转载自blog.csdn.net/helloworld_dream/article/details/81462876