当前位置:网站首页>Ubuntu安装配置PostgreSQL(18.04)
Ubuntu安装配置PostgreSQL(18.04)
2022-06-26 12:32:00 【灯笼只能来教室体验生活】
写在前面
使用的Ubuntu版本:18.04
安装
安装postgresql
$ sudo apt-get install postgresql如果失败可以更新一下包
sudo apt-get update
安装成功后,可以查看psql的版本
psql --version如果安装成功则输出
psql (PostgreSQL) 9.5.25
可以看出,这里的PostgreSQL版本为
9.5安装成功后,postgresql会自动创建:一个数据库用户
postgres(默认无密码)、一个数据> 库postgres、一个Linux用户postgres修改一下Linux用户
postgres的密码sudo passwd postgres切换到Linux用户
postgressu postgres进入数据库命令行
psql执行成功则输出
psql (9.5.25) Type "help" for help. postgres=#Postgresql的服务默认是开启的,如果没有,可以使用以下命令:
sudo /etc/init.d/postgresql start # 开启服务 sudo /etc/init.d/postgresql stop # 关闭服务 sudo /etc/init.d/postgresql restart # 重启服务
查看
Postgresql的数据库目录(数据存储在哪)在psql的命令行下,执行
SHOW data_directory;postgres=# SHOW data_directory; data_directory ------------------------------ /var/lib/postgresql/9.5/main (1 row)/var/lib/postgresql/9.5/main就是数据库目录
配置(可选)
要使其他计算机能够连接到你的 PostgreSQL 服务器
编辑该文件
sudo vi /etc/postgresql/9.5/main/postgresql.conf/etc/postgresql/
9.5/main/postgresql.conf其中
9.5是PostgreSQL的版本,要根据本地的版本而定找到
*#listen_addresses = 'localhost'*,修改为listen_addresses = '*'如果要允许 IPv4 和 IPv6 连接,请将 ‘localhost’ 替换为 ‘::’
listen_addresses = '::'
修改数据库目录
创建一个数据库目录(你需要的位置)
mkdir 目录名例如我创建的是
mkdir /home/test/pg_db关闭Postgresql服务
sudo service postgresql stop复制数据(从默认数据库目录复制到你指定的数据库目录)
sudo cp -rf postgresql的默认数据库目录 你指定的数据库目录我执行的是
sudo cp -rf /var/lib/postgresql/9.5/main /home/test/pg_db权限设置
sudo chown -R postgres:postgres 你指定的数据库目录 sudo chmod 700 你指定的数据库目录我执行的是
sudo chown -R postgres:postgres /home/test/pg_db sudo chmod 700 /home/test/pg_db修改postgresql的
data_directory(配置文件中指定的数据库目录)sudo vi /etc/postgresql/9.5/main/postgresql.conf将
data_directory = '/var/lib/postgresql/9.5/main' # use data in another directory修改为:data_directory = '你指定的数据库目录'我执行的是
data_directory = '/home/test/pg_db'启动Postgresql服务
sudo service postgresql start
边栏推荐
- Notice on printing and Distributing Measures for supporting strategic emerging industries and future industrial cluster development in Futian District, Shenzhen
- Scala-day01- companion objects and HelloWorld
- 证券账户可以开通 开户安全吗
- VMware virtual machine bridging mode can not access the campus network "suggestions collection"
- Scala-day05-set
- Demand scale forecast and investment competitiveness analysis report of China's new material market 2022-2028
- 11、 Box styles and user interface
- Laravel subdomain accesses different routing files and different modules
- Investment forecast and development strategy analysis report of China's rural sewage treatment industry in 2022
- Basic principle of MOS tube and important knowledge points of single chip microcomputer
猜你喜欢

4. N queen problem

11、 Box styles and user interface

Matlab programming example: how to count the number of elements in a cell array

Introduction to the four major FPGA manufacturers abroad

PHP uses laravel pay component to quickly access wechat jsapi payment (wechat official account payment)
![[redis series] redis learning 16. Redis Dictionary (map) and its core coding structure](/img/d2/a6cbb0abe9e04c412d1f6021430528.png)
[redis series] redis learning 16. Redis Dictionary (map) and its core coding structure

【Redis 系列】redis 学习十六,redis 字典(map) 及其核心编码结构

Jmeter响应时间和tps监听器使用教程

Laravel subdomain accesses different routing files and different modules

Loggie encoding and newline character test
随机推荐
Which is safer and better for great wisdom to open an account
I'd like to know what preferential activities are available for stock account opening? Is it safe to open an account online?
HUST网络攻防实践|6_物联网设备固件安全实验|实验三 FreeRTOS-MPU 保护绕过
Precautions for opening a securities account is it safe to open an account
证券账户可以开通 开户安全吗
Mysql8 master-slave replication
Vscode solves the problem of Chinese garbled code
VMware virtual machine bridging mode can not access the campus network "suggestions collection"
Operation analysis and investment prospect research report of China's organic chemical raw material manufacturing industry 2022-2028
Five trends of member marketing of consumer goods enterprises in the future
Investment planning and forecast report on the future direction of China's smart agriculture during the 14th five year plan (2022)
[redis series] redis learning 16. Redis Dictionary (map) and its core coding structure
Xiaolong 888 was released, Xiaomi 11 was launched, and 14 manufacturers carried it in the first batch!
[probability theory] conditional probability, Bayesian formula, correlation coefficient, central limit theorem, parameter estimation, hypothesis test
Assembly language (7) operation instruction
Lintcode 130 · stacking
24 database interview questions that must be mastered!
Loggie encoding and newline character test
Jmeter响应时间和tps监听器使用教程
What software is flush? Is online account opening safe?