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
相关推荐
dragon_perfect34 分钟前
adoc(asciidoc)转为markdown的方法,把.adoc文件转换为markdown格式
linux·运维·deepseek本地知识库
编码小笨猪7 小时前
浅谈Linux中一次系统调用的执行过程
linux·服务器·c++
早起鸟儿8 小时前
docker-Dockerfile 配置
java·linux·运维·docker
光电的一只菜鸡10 小时前
ubuntu之坑(十四)——安装FFmpeg进行本地视频推流(在海思平台上运行)
ubuntu·ffmpeg·音视频
love530love11 小时前
是否需要预先安装 CUDA Toolkit?——按使用场景分级推荐及进阶说明
linux·运维·前端·人工智能·windows·后端·nlp
m0_6948455712 小时前
日本云服务器租用多少钱合适
linux·运维·服务器·安全·云计算
一心09212 小时前
Linux部署bmc TrueSight 监控agent步骤
linux·运维·服务器·监控·bmc truesight
Florence2312 小时前
linux中执行脚本命令的source和“.”和“./”的区别
linux·运维·服务器
白日依山尽yy12 小时前
Linux02
linux·运维·服务器
liulilittle13 小时前
通过高级处理器硬件指令集AES-NI实现AES-256-CFB算法并通过OPENSSL加密验证算法正确性。
linux·服务器·c++·算法·安全·加密·openssl