当前位置:网站首页>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
边栏推荐
- How do consumer goods enterprises formulate membership interests?
- Omnichannel membership - tmall membership 2: frequently asked questions
- redis通过6379端口无法连接服务器
- Analysis report on China's photovoltaic inverter market prospect forecast and investment strategy recommendations in 2022
- Pre knowledge of hash table -- binary search tree
- 2、 MySQL Foundation
- Investment forecast and development strategy analysis report of China's rural sewage treatment industry in 2022
- Polarismesh series articles - concept series (I)
- The most complete kubernetes core command of the latest version so far
- MOS管基本原理,单片机重要知识点
猜你喜欢

Ctfshow web getting started command execution web75-77

New routing file in laravel framework

leetcode 715. Range 模块 (hard)

Scala-day06- pattern matching - Generic

2021 q3-q4 investigation report on the use status of kotlin multiplatform

MOS管基本原理,单片机重要知识点

Mysql8 master-slave replication

Using the methods in the repository to solve practical problems
![Random numbers in leetcode 710 blacklist [random numbers] the leetcode path of heroding](/img/58/2a56c5c9165295c830082f8b05dd98.png)
Random numbers in leetcode 710 blacklist [random numbers] the leetcode path of heroding

Introduction to the four major FPGA manufacturers abroad
随机推荐
Introduction to the strongest swarm cluster one click deployment + hydrogen bomb level container management tool
Polarismesh series articles - concept series (I)
What software is flush? Is online account opening safe?
Spark-day01- get started quickly
NFS shared storage service installation
I'd like to know what preferential activities are available for stock account opening? Is it safe to open an account online?
Lintcode 130 · stacking
What are the top ten securities companies? Is it safe to open a mobile account?
Build Pikachu shooting range and introduction
ctfshow web入门 命令执行web75-77
VMware虚拟机 桥接模式 无法上网 校园网「建议收藏」
redis通过6379端口无法连接服务器
Ad - update the modified PCB package to the current PCB
File decryption in webgame development
Examples of how laravel uses with preload (eager to load) and nested query
UDP协议详解[通俗易懂]
Five trends of member marketing of consumer goods enterprises in the future
CG bone animation
Pre knowledge of hash table -- binary search tree
Realize microservice load balancing (ribbon)