当前位置:网站首页>How to install postgresql and configure remote access in ubuntu environment
How to install postgresql and configure remote access in ubuntu environment
2022-08-04 14:04:00 【theskylife】
1.更新ubuntu包
sudo apt-get update
sudo apt-get upgrade
2.安装官方源
# 创建文件存储库配置
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
sudo apt-get -y install postgresql
以上命令成功运行后,证明postgresql已经正常安装,It will start automatically after the installation is completepostgresql的服务.It can be viewed through the following informationpostgresql的信息
# 查看postgresql版本
sudo -u postgres psql -c "SELECT version();"
# 查看postgresql服务是否启动
service postgresql status
3.进行数据库配置
3.1 创建用户账号密码
在ubuntu上PostgreSQL数据库以后,A computer user is automatically createdpostgre,The following operations are based on this account.
运行以下命令,使用postgre用户登录postgresql
# 切换用户
sudo su postgres
# 进入交互界面
psql
进行postgresqlafter the interactive interface,User creation can be done by running the following information
-- Create an account without a password-root
create role root;
-- Create an account with a password-root
create user root with 'root123';
-- 显示所有用户,并查看是否创建成功
\du
-- 更改postgresql密码,如修改root账号的密码
alter user root with password 'root123#';
3.2 创建数据库
-- 创建数据库(test)
create database test;
-- 删除数据库(test)
drop database test;
-- 查询所有数据库
\l
-- 切换数据库test
\c test
3.3 创建schema
-- 创建schema(ods),以下写法均可
create schema ods;
create schema if not exists ods;
-- 为某个用户(root2)创建market
create schema market authorization roo2;
-- 查看当前数据库下的所有schema
select * from information_schema.schemata;
-- 删除schema(ods)
drop schema if exists ods;
3.4 用户权限授权
After creating the user password,Permissions can be granted to users with the following commands
-- 给用户root赋予超级用户权限
alter user root with superuser;
-- 给用户root2Grant ordinary permissions
alter user root2 with privileges;
-- Give all permissions to the database to the userroot
grant all privileges on database test to root;
-- 把某schema下(ods)的所有表(test用户下)All permissions are given to the userroot2
grant all on all tables in schema ods to root2;
-- put a table(test_table)All permissions are given to the userroot2
grant all on test_table to root2;
-- put a table(test_table)The query permission is given to the userroot2
grant select on table test_table to root2;
-- 撤销用户root2的某个数据库(test)权限;
revoke all on database test from root2;
-- 撤销用户root2某个schema(ods)Modifications to all tables below(update)权限;
revoke update on all tables in schema ods from root2;
-- 撤销用户root2某张表(test_table)的所有权限
revoke privileges on test_table from root2;
-- put a table(test_table)given by the ownerroot2
alter table test_table owner to root2;
-- 允许用户(root)登录
ALTER ROLE root WITH LOGIN;
-- 禁止用户(root)登录
ALTER ROLE root WITH NOLOGIN;
3.5 配置远程访问
由于postgresqlA username is added by default during installationpostgres的ubuntu系统用户,So you need to delete it with another account firstpostgres用户的密码,Then configure your own password.
# 删除postgres用户的密码
sudo passwd -d postgres
# 设置postgres用户的密码
sudo -u postgres passwd
After configuring the password,编辑/etc/postgresq/12/main/postgresql.conf文件
sudo vim /etc/postgresql/12/main/postgresql.conf
in the above configuration filepostgresql.conf中添加以下内容:
listen_addresses = '*'
password_encryption = scram-sha-256
运行以下命令,编辑/etc/postgresq/12/main/pg_hba.conf文件
sudo vim /etc/postgresql/14/main/pg_hba.conf
在pg_hba.conf文件末尾追加以下内容:
host all all 0.0.0.0/0 scram-sha-256
添加完成后,保存退出,然后重启postgresql 服务.
sudo service postgresql restart
3.6使用Navicat链接
Use the information obtained above,成功链接postgresql数据库.
3.7 卸载Navicat
# 移除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
边栏推荐
- 华为手机切换屏幕效果_华为p40页面切换效果怎么换
- 自监督学习未来是掩码自编码器?KAIST最新《自监督学习掩码自编码器》研究进展
- 人像分割技术解析与应用
- 阴影初始化【5】
- "Social Enterprises Conducting Civilian Personnel Training Specifications" group standard on the shelves of Xinhua Bookstore
- TS---类型设置
- Analysis and application of portrait segmentation technology
- Rust 从入门到精通04-变量
- PAT甲级:1040 Longest Symmetric String
- Install mysql on k8s
猜你喜欢
随机推荐
如何确定异步 I/O 瓶颈
【毕设选题推荐】机器人工程专业毕设选题推荐
zabbix自定义图形
odoo13 note point
阴影初始化【5】
Niuke.com Brush Question Record || Linked List
零基础可以转行软件测试吗 ?这篇文章告诉你
Centos7 install mysql version rapidly
化算力为战力:宁夏中卫的数字化转型启示录
k8s上安装mysql
第四讲 SVN
博途200/1500PLC多段曲线控温FB(支持40段控温曲线、段曲线搜索、暂停、跳段等功能)
爬虫——selenium基本使用、无界面浏览器、selenium的其他用法、selenium的cookie、爬虫案例
封装、继承、多态的联合使用实现不同等级学生分数信息的统计
[Niu Ke brush questions-SQL big factory interview questions] NO5. Analysis of a treasure store (e-commerce model)
解题-->在线OJ(十八)
电子行业MES管理系统有哪些特殊功能
LeetCode 1403 Minimum subsequence in non-increasing order [greedy] HERODING's LeetCode road
LeetCode 1403 非递增顺序的最小子序列[贪心] HERODING的LeetCode之路
FreeConfig.h文件