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
相关推荐
zhuzewennamoamtf29 分钟前
Linux SPI设备驱动
android·linux·运维
春日见29 分钟前
在虚拟机上面无法正启动机械臂的控制launch文件
linux·运维·服务器·人工智能·驱动开发·ubuntu
松涛和鸣1 小时前
Linux Makefile : From Basic Syntax to Multi-File Project Compilation
linux·运维·服务器·前端·windows·哈希算法
Predestination王瀞潞2 小时前
JDK安装及环境变量配置
java·linux·开发语言
再睡一夏就好2 小时前
深入Linux线程:从轻量级进程到双TCB架构
linux·运维·服务器·c++·学习·架构·线程
小小药2 小时前
09-vmware配置虚机连接互联网-nat模式
linux·运维·centos
Bright Xu3 小时前
Qemu 安装 LoongArch架构 Fedora Remix F42 Linux系统
linux·loongarch·国产cpu
莫白媛3 小时前
Linux创作笔记综合汇总篇
linux·运维·笔记
studytosky3 小时前
Linux系统编程:深度解析 Linux 进程,从底层架构到内存模型
linux·运维·服务器·开发语言·架构·vim
wdfk_prog3 小时前
[Linux]学习笔记系列 -- [fs]buffer
linux·笔记·学习