首页 » Linux » PostgreSQL 安装

PostgreSQL 安装

 

一、安装

可以参考官网:https://www.postgresql.org/download/linux/redhat/ 官网上有不同系统不同的安装方法

安装完之后,如果需要改动数据库存储位置,需要在启动文件里进行更改就可以了。而且需要建立对应目录和更改相应权限 。

如centos7安装 11版本:

yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum install postgresql11-server postgresql11
/usr/pgsql-11/bin/postgresql-11-setup initdb
systemctl enable postgresql-11
systemctl start postgresql-11

 二、配置

修改访问:

文件:postgresql.conf

位置:/var/lib/pgsql/data/postgresql.conf

添加/修改:在所有IP地址上监听,从而允许远程连接到数据库服务器:

listening_address: ‘*’

 

文件:pg_hba.conf

位置:/var/lib/pgsql/data/pg_hba.conf

添加/修改:允许任意用户从任意机器上以密码方式访问数据库,把下行添加为第一条规则:

host    all             all             0.0.0.0/0               md5

 

三、修改postgres数据库用户密码

su - postgres
psql
alter user postgres password '123';

登录:psql  -U  postgres  -d  postgres  -h  127.0.0.1  -p  5432

 

四、配置参考

64G内存配置

listen_addresses = '*'
max_connections = 200
shared_buffers = 24GB
work_mem = 128MB
maintenance_work_mem = 256MB
autovacuum_work_mem = 256MB
dynamic_shared_memory_type = posix
fsync = on
wal_buffers = 256MB
max_wal_size = 1GB
min_wal_size = 80MB
effective_cache_size = 12GB
log_destination = 'stderr'
logging_collector = on
log_directory = 'log'
log_filename = 'postgresql-%a.log'
log_truncate_on_rotation = on
log_rotation_age = 1d
log_rotation_size = 0
log_line_prefix = '%m [%p] '
log_timezone = 'Asia/Shanghai'
datestyle = 'iso, mdy'
timezone = 'Asia/Shanghai'
lc_messages = 'en_US.UTF-8'
lc_monetary = 'en_US.UTF-8'
lc_numeric = 'en_US.UTF-8'
lc_time = 'en_US.UTF-8'
default_text_search_config = 'pg_catalog.english'
shared_preload_libraries = '/usr/pgsql-11/lib/plugin_debugger.so'

参考:

https://blog.csdn.net/zhangzeyuaaa/article/details/77941039

https://blog.csdn.net/mbshqqb/article/details/78622167

http://www.ruanyifeng.com/blog/2013/12/getting_started_with_postgresql.html

 

 

 

 

原文链接:PostgreSQL 安装,转载请注明来源!

2