环境:Ubuntu Xenial (16.04)     !!! CentOS 参考这里   

sudo apt-get update
sudo apt-get upgrade
apt-get install htop wget software-properties-common

默认: sudo apt-get install postgresql (9.5版本)

For any Ubuntu version you need to can do this by the official PostgreSQL Apt Repository.

Ubuntu Xenial (16.04)

sudo add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main"
wget --quiet -O -
https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-9.6
Ubuntu Trusty (14.04)

sudo add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main"
wget --quiet -O -
https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-9.6
Ubuntu Precise (12.04)

sudo add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main"
wget --quiet -O -
https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-9.6

# 配置 PostgreSQL

安装完成后,默认会:
(1)创建名为"postgres"的Linux用户
(2)创建名为"postgres"、不带密码的默认数据库账号作为数据库管理员
(3)创建名为"postgres"的表
默认配置信息:
Creating new cluster 9.6/main ...
  config /etc/postgresql/9.6/main
  data   /var/lib/postgresql/9.6/main
  locale en_US.UTF-8
  socket /var/run/postgresql
  port   5432

# PostgreSQL 命令

#查看版本
psql -- version
#切换用户
sudo -u postgres psql
#修改密码
ALTER USER postgres WITH ENCRYPTED PASSWORD 'XXX';

修改密码本地环境生效配置
#修改pg_hba.conf
    #local   all   postgres   peer
    local   all   postgres   md5
#重启服务
sudo service postgresql restart
#登陆
psql -U postgres 

#修改Linux用户的密码
sudo passwd postgres
#配置数据库以允许远程连接访问
sudo vi /etc/postgresql/9.4/main/postgresql.conf
# 增加 listen_addresses = '*'
sudo vi /etc/postgresql/9.4/main/pg_hba.conf

#修改 IP4
#host all all 127.0.0.1/32 md5
host all all 0.0.0.0/0 md5

# DO NOT DISABLE! # If you change this first entry you will need to make sure that the # database superuser can access the database using some other method. # Noninteractive access to all databases is required during automatic # maintenance (custom daily cronjobs, replication, and similar tasks). # # Database administrative login by Unix domain socket local all postgres peer # TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only local all all peer # IPv4 local connections: #host all all 127.0.0.1/32 md5 host all all 0.0.0.0/0 md5 # IPv6 local connections: host all all ::1/128 md5 # Allow replication connections from localhost, by a user with the # replication privilege. #local replication postgres peer #host replication postgres 127.0.0.1/32 md5 #host replication postgres ::1/128 md5
privilege

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
  • 2021-06-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-02
  • 2021-09-18
  • 2021-12-24
相关资源
相似解决方案