Ubuntu 20.04 postgresql

安装命令

shell 复制代码
$ sudo apt-get update
$ sudo apt-get install -y postgresql

查看postgresql版本

shell 复制代码
$ psql --version
psql (PostgreSQL) 12.22 (Ubuntu 12.22-0ubuntu0.20.04.3)

查看系统用户组是否存在postgres

shell 复制代码
$ getent group postgres
postgres:x:115:
$ getent passwd postgres
postgres:x:107:115:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash

修改postgres USER密码

shell 复制代码
$ sudo -i -u postgres
[sudo] password for pi:
$ psql
postgres=# ALTER USER postgres WITH PASSWORD '123456';
ALTER ROLE

根据sql导入数据库

shell 复制代码
$ sudo -u postgres psql -d postgres -f ./pg_initial.sql

卸载

shell 复制代码
$ sudo systemctl stop postgresql
$ sudo apt-get remove --purge postgresql\*
$ sudo rm -rf /var/lib/postgresql/
$ sudo rm -rf /etc/postgresql/

Dockerfile

使用alphine所构建出的docker image尺寸较小

Dockerfile 复制代码
FROM postgres:alpine3.19

COPY docker-entrypoint.sh /usr/local/bin/
ADD pg_initial.sql /docker-entrypoint-initdb.d/
RUN chmod 0777 /docker-entrypoint-initdb.d/pg_initial.sql && chown postgres:postgres /docker-entrypoint-initdb.d/pg_initial.sql

EXPOSE 5432
相关推荐
CCCCCCCCharlie36 分钟前
Linux进程控制四大核心操作
linux·开发语言
nazisami1 小时前
操作系统进程状态
linux·进程状态
xbzb1 小时前
Linux 文件查找命令 locate 与 find 完全指南
linux·运维
ITxiaobing20231 小时前
IP 定位服务选型指南:从准确率到工程落地的技术考察
linux·服务器·网络
wuyk5551 小时前
【Socket 进阶之路】第 9 章 Linux 网络服务量产稳定性优化|心跳保活、TIME_WAIT、SO_LINGER、内存池、断线重连、完整异常防护框架
linux·服务器·开发语言·网络·物联网
Julien20041 小时前
Docker 容器存储原理(一)
linux·运维·服务器·ssh·学习方法
thinking_talk1 小时前
WorkBuddy应用生成背后的数据层:腾讯云PG
postgresql·腾讯云·云数据库
半仙白桑1 小时前
内核篇第四讲:wait () 函数
linux·wait函数
zhangrelay1 小时前
《机器人控制器设计与编程》课程习题资料-2026
linux·笔记·学习·ubuntu
邪修king1 小时前
Re:Linux 系统篇(三十四):进程间通信开篇Chapter1 —— 匿名管道 pipe 深度拆解与代码实战
android·linux·运维·开发语言