ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

Ubuntu安装PostgreSQL

2021-06-12 22:58:09  阅读:200  来源: 互联网

标签:PostgreSQL postgres sudo apt postgis Ubuntu postgresql 安装


更新ubuntu18.04

sudo apt update
sudo apt -y upgrade

//升级后重启
sudo reboot

添加PostgreSQL存储库

//创建文件存储库配置:
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
//导入存储库签名密钥:
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
// 更新软件包列表:
sudo apt-get update

安装默认的postgresql

//更新apt包索引
sudo apt update
//安装PostgreSQL服务器和contrib软件包
sudo apt install postgresql postgresql-contrib
//安装完成后,PostgreSQL服务将启动,要验证安装,请使用psql工具打印服务器版本
sudo -u postgres psql -c "SELECT version();"
psql --version
//psql是一个交互式终端程序,可让你与PostgreSQL服务器进行交互

安装postgis

sudo apt update
// 确定postgresql版本,安装指定版本
sudo apt install postgis postgresql-12-postgis-3.0
#查看ubuntu版本信息
  lsb_release -a
  
  #查看当前支持的postgresql版本
  sudo apt-cache search postgresql 
  
  #安装postgresql-10
  sudo apt-get install postgresql-10 postgresql-contrib
  
  #查看apt-get库中的软件版本
  sudo apt-cache search postgis
  
  #安装postgis
  sudo apt-get install postgis
  
  #登陆postgresql
  sudo -u postgres psql
  
  #修改i登陆postgresql密码
  alter user postgres with password 'postgres';

PostgreSQL会创建一个默认的linux用户postgres,修改该用户密码的方法如下:

#删除用户postgres的密码
sudo  passwd -d postgres

#设置用户postgres的密码
sudo -u postgres passwd 

启动PostgreSQL服务器的远程访问

// 默认情况下,PostgreSQL服务器仅在本地接口127.0.0.1上侦听
sudo vim /etc/postgresql/12/main/postgresql.conf
//修改如下
listen_addresses = '*' 
//保存文件并重启PostgreSQL服务
sudo service postgresql restart
//使用ss使用程序验证更改
ss -nlt | grep 5432

ubuntu---postgresql

输出应显示PostgreSQL服务器在所有接口(0.0.0.0)上进行侦听

最后一步是通过编辑pg_hba.conf文件将服务器配置为接受远程登录

vim /etc/postgresql/11/main/pg_hba.conf
# TYPE  DATABASE        USER            ADDRESS                 METHOD
# The user jane will be able to access all databases from all locations using an md5 password
host    all             all            0.0.0.0/0                md5
# The user jane will be able to access only the janedb from all locations using an md5 password
host    janedb          jane            0.0.0.0/0                md5
# The user jane will be able to access all databases from a trusted location (192.168.1.134) without a password
host    all             jane            192.168.1.134            trust

ubuntu安装pgadmin4

sudo apt-get install pgadmin4
//启动pgadmin4
pgadmin4

Ubuntu完整卸载postgresql

删除相关的安装

sudo apt-get --purge remove postgresql|*

删除配置及相关文件

sudo rm -r /etc/postgresql/
sudo rm -r /etc/postgresql-common/
sudo rm -r /var/lib/postgresql/

删除用户和所在组

sudo userdel -r postgres
sudo groupdel postgres

删除postgis

sudo apt-get --purge remove postgis

标签:PostgreSQL,postgres,sudo,apt,postgis,Ubuntu,postgresql,安装
来源: https://blog.csdn.net/qq_36213352/article/details/117856767

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有