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
相关推荐
晚风吹人醒.16 分钟前
SSH远程管理及访问控制
linux·运维·ssh·scp·xshell·访问控制·远程管理
Uncertainty!!2 小时前
Linux多用户情况下个别用户输入密码后黑屏
linux·远程连接
necessary6532 小时前
使用Clion查看linux环境中的PG源码
linux·运维·服务器
小猪佩奇TONY3 小时前
Linux 内核学习(14) --- linux x86-32 虚拟地址空间
linux·学习
Lam㊣3 小时前
Centos 7 系统docker:更换镜像源
linux·docker·centos
FL16238631293 小时前
win11+WSL+Ubuntu-xrdp+远程桌面闪退+黑屏闪退解决
linux·运维·ubuntu
石头5303 小时前
Kubernetes监控全栈解决方案:从零搭建Prometheus+Grafana监控体系
linux
ha20428941944 小时前
Linux操作系统学习记录之---TcpSocket
linux·网络·c++·学习
AOwhisky4 小时前
Linux逻辑卷管理:从“固定隔间”到“弹性存储池”的智慧
linux·运维·服务器
刘一说5 小时前
TypeScript 与 JavaScript:现代前端开发的双子星
javascript·ubuntu·typescript