Ubuntu上安装postgresql
官网链接
https://www.postgresql.org/download/linux/ubuntu/
Ubuntu19.04 安装 postgresql 11
查看Ubuntu版本
lsb_release -c
得到的结果是disco
修改文件
vi /etc/apt/sources.list.d/pgdg.list
写入以下记录
deb [arch=amd64] http://apt.postgresql.org/pub/repos/apt/ disco-pgdg main
注意上面如果没有中括号后面会报
Skipping acquire of configured file 'main/binary-i386/Packages' as repository 'http://apt.postgresql.org/pub/repos/apt disco-pgdg InRelease' doesn't support architecture 'i386'
上面两个命令合到一起就是
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
执行命令
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
切换数据源
修改/etc/apt/sources.list改为阿里的源,这样也可以不用执行上面的语句
deb http://mirrors.aliyun.com/ubuntu/ eoan main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ eoan main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ eoan-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ eoan-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ eoan-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ eoan-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ eoan-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ eoan-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ eoan-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ eoan-proposed main restricted universe multiverse
下载安装
apt install -y postgresql-server-11
设置密码
切换至postgres账号使用psql登录
ALTER USER postgres WITH PASSWORD 'mima';
免密登录
修改~/.pgpass文件,增加一行127.0.0.1:5432:*:postgres:mima
具体含义参考官网
开启远程访问
修改postgresql.conf文件
listen_addresses = '*'
切换账号操作重启db
su - postgres -c '/usr/pgsql-11/bin/pg_ctl restart -D /data/pgdata'
修改PATH
临时修改
export PATH="$PATH:/usr/pgsql-11/bin/"
永久修改
修改/etc/environment