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
相关推荐
魂尾ac7 分钟前
Centos Docker 安装(100%成功)
linux·docker·centos
九皇叔叔19 分钟前
【7】PostgreSQL 事务
数据库·postgresql
ajassi200022 分钟前
开源 C# .net mvc 开发(八)IIS Express轻量化Web服务器的配置和使用
linux·开源·c#·mvc·.net
張萠飛35 分钟前
Linux中程序的limits中的Max open files的配置由哪些参数决定
linux·运维·服务器
KoiHeng3 小时前
操作系统简要知识
linux·笔记
Johny_Zhao7 小时前
Docker + CentOS 部署 Zookeeper 集群 + Kubernetes Operator 自动化运维方案
linux·网络安全·docker·信息安全·zookeeper·kubernetes·云计算·系统运维
小毛驴8507 小时前
Linux 后台启动java jar 程序 nohup java -jar
java·linux·jar
一心0928 小时前
ubuntu 20.04.6 sudo 源码包在线升级到1.9.17p1
运维·ubuntu·sudo·漏洞升级
好好学习啊天天向上8 小时前
世上最全:ubuntu 上及天河超算上源码编译llvm遇到的坑,cmake,ninja完整过程
linux·运维·ubuntu·自动性能优化
tan180°9 小时前
MySQL表的操作(3)
linux·数据库·c++·vscode·后端·mysql