Ubuntu 20.04 postgresql

安装命令

$ sudo apt-get update
$ sudo apt-get install -y postgresql

查看postgresql版本

$ psql --version
psql (PostgreSQL) 12.22 (Ubuntu 12.22-0ubuntu0.20.04.3)

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

$ getent group postgres
postgres:x:115:
$ getent passwd postgres
postgres:x:107:115:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash

修改postgres USER密码

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

根据sql导入数据库

$ sudo -u postgres psql -d postgres -f ./pg_initial.sql

卸载

$ 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尺寸较小

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

你可能感兴趣的:(ubuntu,postgresql,linux)