ubuntu 18 虚拟机安装(4)安装 postgres sql 数据库

ubuntu 18 虚拟机安装(4)安装 postgres sql 数据库

如何在Ubuntu 20.04上安装和使用TimescaleDB
https://devpress.csdn.net/ubuntu/62ecdfba19c509286f417923.html

如何查看PostgreSQL的版本
https://blog.csdn.net/lee_vincent1/article/details/138731465
postgres 查看全部数据库
https://blog.csdn.net/xie__jin__cheng/article/details/138653002
Ubuntu18.04安装Postgresql与配置
https://blog.csdn.net/b285795298/article/details/130759531

https://www.postgresql.org/download/linux/ubuntu/

https://www.cnblogs.com/xu360/articles/16860260.html
How To Install and Use PostgreSQL on Ubuntu 18.04
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04

postgres新增用户、创建新库
https://blog.csdn.net/qq_34322136/article/details/135624871
https://www.jb51.net/article/204207.htm

2.设置数据库时间和时区
(1). 通过命令
PRC为东八区 北京时间 UTC+8
Asia/Shanghai为东八区 上海时间 GMT+8
但是通过这种方式设置时区是session级别的,退出会话会失效

https://blog.csdn.net/qq_45658339/article/details/124431612

查看所有用户

cat /etc/passwd

查看所有用户个数

cat /etc/passwd | wc -l
31

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

The following additional packages will be installed:
  libpq5 libsensors4 postgresql-10 postgresql-client-10 postgresql-client-common postgresql-common ssl-cert sysstat
Suggested packages:
  lm-sensors postgresql-doc locales-all postgresql-doc-10 libjson-perl openssl-blacklist isag
The following NEW packages will be installed:
  libpq5 libsensors4 postgresql postgresql-10 postgresql-client-10 postgresql-client-common postgresql-common ssl-cert sysstat
0 upgraded, 9 newly installed, 0 to remove and 45 not upgraded.
Adding user postgres to group ssl-cert
Creating config file /etc/postgresql-common/createcluster.conf with new version
Building PostgreSQL dictionaries from installed myspell/hunspell packages...
Removing obsolete dictionary files:
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /lib/systemd/system/postgresql.service.
Setting up libsensors4:amd64 (1:3.4.0-4ubuntu0.1) ...
Setting up postgresql-client-10 (10.23-0ubuntu0.18.04.2) ...
update-alternatives: using /usr/share/postgresql/10/man/man1/psql.1.gz to provide /usr/share/man/man1/psql.1.gz (psql.1.gz) in auto mode
Setting up sysstat (11.6.1-1ubuntu0.2) ...

Creating config file /etc/default/sysstat with new version
update-alternatives: using /usr/bin/sar.sysstat to provide /usr/bin/sar (sar) in auto mode
Created symlink /etc/systemd/system/multi-user.target.wants/sysstat.service → /lib/systemd/system/sysstat.service.
Setting up postgresql-10 (10.23-0ubuntu0.18.04.2) ...
Creating new PostgreSQL cluster 10/main ...
/usr/lib/postgresql/10/bin/initdb -D /var/lib/postgresql/10/main --auth-local peer --auth-host md5
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/10/main ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... Asia/Shanghai
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

Success. You can now start the database server using:

    /usr/lib/postgresql/10/bin/pg_ctl -D /var/lib/postgresql/10/main -l logfile start

Ver Cluster Port Status Owner    Data directory              Log file
10  main    5432 down   postgres /var/lib/postgresql/10/main /var/log/postgresql/postgresql-10-main.log
update-alternatives: using /usr/share/postgresql/10/man/man1/postmaster.1.gz to provide /usr/share/man/man1/postmaster.1.gz (postmaster.1.gz) in auto mode
Setting up postgresql (10+190ubuntu0.1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for ureadahead (0.100.0-21) ...
Processing triggers for libc-bin (2.27-3ubuntu1.5) ...
Processing triggers for systemd (237-3ubuntu10.57) ...

sudo systemctl status postgresql
sudo systemctl start postgresql
sudo systemctl stop postgresql

postgresql.service - PostgreSQL RDBMS
   Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
   Active: active (exited) since Thu 2024-06-27 14:29:57 CST; 10min ago
 Main PID: 2387 (code=exited, status=0/SUCCESS)
    Tasks: 0 (limit: 4623)
   CGroup: /system.slice/postgresql.service

Jun 27 14:29:57 jack systemd[1]: Starting PostgreSQL RDBMS...
Jun 27 14:29:57 jack systemd[1]: Started PostgreSQL RDBMS.

psql --version

psql (PostgreSQL) 10.23 (Ubuntu 10.23-0ubuntu0.18.04.2)

在Ubuntu中安装Postgresql之后,会自动注册服务,并随操作系统自动启动。
在Ubuntu中安装Postgresql之后,会自动添加一个postgresql的操作系统的用户,密码是随机的。并且会自动生成一个名字为postgresql的数据库,用户名也是postgresql,密码也是随机的。
用postgres用户登录:

sudo -u postgres psql

或者是

sudo su - postgres
psql

修改PostgresSQL数据库配置

vi /etc/postgresql/10/main/postgresql.conf

1.1 修改配置文件

vi /etc/postgresql/10/main/postgresql.conf

1.监听任何地址访问,修改连接权限

#listen_addresses = 'localhost' 改为 
listen_addresses = '*'

2.启用密码验证

#password_encryption = md5		# md5 or scram-sha-256
password_encryption = md5		# md5 or scram-sha-256
#shared_preload_libraries = ''		# (change requires restart)
shared_preload_libraries = 'timescaledb'		# (change requires restart)
  1. 时区这个不确定 要不要修改
log_timezone = 'Asia/Shanghai'
log_timezone = 'PRC'

  1. 时区不确定要不要修改
timezone = 'Asia/Shanghai'
timezone = 'PRC'

sudo vi /etc/postgresql/10/main/pg_hba.conf


# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
host    all             all             0.0.0.0/0               md5

Ubuntu的默认软件包存储库中没有TimescaleDB,因此在此步骤中,您将从TimescaleDB Personal Packages Archive(PPA)安装它。

First, add Timescale’s APT repository:

首先,添加Timescale的APT存储库:

sudo add-apt-repository ppa:timescale/timescaledb-ppa

Confirm this action by hitting the ENTER key.

通过按ENTER键确认此操作。

Next, refresh your APT cache to update your package lists:

接下来,刷新您的APT缓存以更新您的软件包列表:

sudo apt update

sudo apt install timescaledb-postgresql-10

现在已安装TimescaleDB并准备使用它。 接下来,您将打开它并在PostgreSQL配置文件中调整与它相关联的一些设置以优化数据库。

添加用户

执行这句话的时候,一定要注意查看,当前是否是测试环境
drop role jack ;
create user jack with password '12345' superuser;
select * from pg_user; 

111

https://blog.csdn.net/ctypyb2002/article/details/79881745

pg_dump -h 127.0.0.1 -U jack-d abc -f abc_bak_2024_06_28.sql

out

Password: 
pg_dump: NOTICE: there are circular foreign-key constraints on this table:
pg_dump:   hypertable
pg_dump: You might not be able to restore the dump without using --disable-triggers or temporarily dropping the constraints.
pg_dump: Consider using a full dump instead of a --data-only dump to avoid this problem.
pg_dump: NOTICE: there are circular foreign-key constraints on this table:
pg_dump:   chunk
pg_dump: You might not be able to restore the dump without using --disable-triggers or temporarily dropping the constraints.
pg_dump: Consider using a full dump instead of a --data-only dump to avoid this problem.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值