ubuntu22.04.3 安装postgresql 16 rc1数据库

一、直接安装

# Create the file repository configuration:

sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

# Import the repository signing key:

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

# Update the package lists:

sudo apt-get update

# Install the latest version of PostgreSQL.

# If you want a specific version, use 'postgresql-12' or similar instead of 'postgresql':

sudo apt-get -y install postgresql

二、源码安装

1、下载源码

https://ftp.postgresql.org/pub/source/v16rc1/postgresql-16rc1.tar.gz

2、解压源文件

tar xf postgresql-16rc1.tar.gz .

3、准备环境,系统必须安装好了gcc make readline zlib 等,建好文件目录

#创建目录
mkdir -p /usr/local/pgsql16rc1
mkdir -p /usr/local/pgsql16rc1/data
#目录授权
sudo chown pgsql:pgsql /usr/local/pgsql16rc1
sudo chown pgsql:pgsql /usr/local/pgsql16rc1/data
#安装依赖库和工具
sudo apt install gcc
sudo apt-get install libreadline-dev
sudo apt-get install zlib1g-dev
sudo apt install make
#配置
./configure --prefix=/usr/local/pgsql16rc1/ --without-icu
#编译安装
make
make install

4、初始化数据库

/usr/local/pgsql16rc1/bin/initdb -D /usr/local/pgsql16rc1/data/

5、启动数据库

/usr/local/pgsql16rc1/bin/pg_ctl -D /usr/local/pgsql16rc1/data/ -l logfile start

6、测试数据库

#创建test库
/usr/local/pgsql16rc1/bin/createdb test
#进入数据库控制台
/usr/local/pgsql16rc1/bin/psql test
test=# \d
test=# \d pg_stat_io
test=# \d pg_stat_all_tables
#创建postgres角色
test=# CREATE ROLE postgres WITH LOGIN PASSWORD 'postgres';
CREATE ROLE
test=# \q

7、配置数据库开放连接

#查看数据库监听端口
sudo netstat -tuln
#查看防火墙状态
sudo ufw status
#编辑postgresql.conf
vim /usr/local/pgsql16rc1/data/postgresql.conf
#修改配置
# - Connection Settings - listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
max_connections = 100 # (change requires restart)
#reserved_connections = 0 # (change requires restart) #编辑pg_hba.conf
# IPv4 local connections:
host all all 0.0.0.0/32 trust #重启数据库
/usr/local/pgsql16rc1/bin/pg_ctl restart -D /usr/local/pgsql16rc1/data -l logfile

8、配置数据库连接账号

/usr/local/pgsql16rc1/bin/psql -U postgres
postgres=> \password postgres
Enter new password for user "postgres":
Enter it again:
postgres=> exit
#添加超级用户
sudo -u postgres /usr/local/pgsql16rc1/bin/createuser --superuser <your_username>
#登录数据库
/usr/local/pgsql16rc1/bin/psql -U your_username -d database
#修改用户密码
ALTER USER your_username WITH PASSWORD 'your_password';
#退出重启发现在还是不需要密码
#此时需要修改一下pg_hba.conf的认证方式,trust修改为md5 ,如果忘记密码可以反过来操作即可
# IPv4 local connections:
host all all 0.0.0.0/32 md5
#修改之后重启数据库,就需要密码登录连接数据库了

9、设置数据库开机启动

#/usr/lib/systemd/system/postgresql-16.service
#创建此文件
[Unit] Description=PostgreSQL database server After=network.target [Service] Type=forking User=pgsql Group=pgsql Environment=PGPORT=5432 Environment=PGDATA=/usr/local/pgsql16rc1/data/ OOMScoreAdjust=-1000 ExecStart=/usr/local/pgsql16rc1/bin/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t 300 ExecStop=/usr/local/pgsql16rc1/bin/pg_ctl stop -D ${PGDATA} -s -m fast ExecReload=/usr/local/pgsql16rc1/bin/pg_ctl reload -D ${PGDATA} -s TimeoutSec=300 [Install] WantedBy=multi-user.target #重新加载
systemctl daemon-reload
#启动数据库
systemctl start postgresql-16.service
#设置开机启动
systemctl enable postgresql-16.service

10、常用操作命令

使用 pg_ctl 命令

pg_ctl 命令为 PostgreSQL 服务端应用程序,可以用来初始化,启动和停止及控制 PostgreSQL 服务器。

pg_ctl 语法格式:

初始化数据库
pg_ctl init[db] [-D DATADIR] [-s] [-o OPTIONS] 启动数据库
pg_ctl start [-D DATADIR] [-l FILENAME] [-W] [-t SECS] [-s] [-o OPTIONS] [-p PATH] [-c] 关闭数据库
pg_ctl stop [-D DATADIR] [-M SHUTDOWN-MODE] [-W] 重启数据库
pg_ctl restart [-D DATADIR] [-m SHUTDOWN-MODE] [-W] [-t SECS] [-s] [-o OPTIONS] [-c] 重新加载 postgresql.conf 或 pg_hba.conf 文件
pg_ctl reload [-D DATADIR] [-s] 查看服务器是否在指定的数据目录运行
pg_ctl status [-D DATADIR] pg_ctl提升 [-D DATADIR] [-W] [-t SECS] [-s] pg_ctl logrotate [-D DATADIR] [-s] pg_ctl杀死信号名PID 命令选项 -D, --pgdata=DATADIR:指定数据库相关文件的数据目录,如果省略,默认读取 PGDATA 环境变量 -s, --silent:静默输出,仅仅输出错误消息 -t, --timeout=SECS:指定等待操作完成的最大延时秒数。默认为 PGCTLTIMEOUT 环境变量的值,如果省略,默认60秒 -V, --版本输出版本信息,然后退出 -w, --wait:等待操作完成,如果操作在延迟时间内未完成,pg_ctl 退出状态为非零 -W, --no-wait:不等待操作完成,不会提示数据库停止是否完成 启动 & 重启选项 -c, --core-files 允许 postgres 生成核心文件 -l, --log=FILENAME:将服务器日志输出追加到 filename中,也叫做服务器日志文件。如果该文件的 umask 设置为077,访问日志文件默认情况下其它用户不可读。 -o, --options=OPTIONS 命令行选项,以传递给 postgres(PostgreSQL 服务器可执行文件)或 initdb -p 路径到POSTGRES通常不是必需的 启动 & 停止选项 -m, --mode=MODE:指定关闭数据库的模式,有三个选项,smart,fast,immediate,省略默认为fast 关库选项 smart:smart模式会等待活动的事务提交结束, 并等待客户端主动断开连接之后关闭数据库 fast:fast模式则会回滚所有活动的事务, 并强制断开客户端的连接之后关闭数据库(默认) 立即:模式立即终止所有服务器进程,当下一次数据库启动时它会首先进入恢复状态(不推荐使用)

ubuntu22.04.3 安装postgresql 16 rc1数据库的更多相关文章

  1. Ubuntu 16.04下安装MacBuntu 16.04 TP 变身Mac OS X主题风格

    Ubuntu 16.04下安装MacBuntu 16.04 TP 变身Mac OS X主题风格 sudo add-apt-repository ppa:noobslab/macbuntu sudo a ...

  2. 带有pwn环境的Ubuntu22.04快速安装

    pwn环境ubuntu22.04快速安装(有克隆vmk) ubuntu更新到了22.04版本,经过本人测试后非常的好(ma)用(fan),该版本和mac很相像,而且用起来也比较丝滑,只不过配置上稍微有 ...

  3. Ubuntu22.04 KubeSphere 安装K8S集群

    Ubuntu22.04 KubeSphere 安装K8S集群_Ri0n的博客-CSDN博客 一.系统环境系统:Ubuntu 22.04集群IP分布hostname 角色 IP地址master mast ...

  4. ubuntu-12.04下安装postgresql

    2013-10-01 20:42:57|    moniter参考资料:Ubuntu 12.04下PostgreSQL-9.1安装与配置详解(在线安装)一.安装postgresqlbamboo@bam ...

  5. ubuntu14.04源代码安装postgresql 9.1

    项目须要使用gisgraphy,怎奈gisgraphy3.0仅仅支持postgis1.5.因此仅仅能安装老版本号的posgresql和postgis了.从postgis的support matrix图 ...

  6. Ubuntu 14.04卸载安装失败的Mysql数据库,以及重新安装配置

    一.删除原来Mysql 1.删除mysql的数据文件 sudo rm /var/lib/mysql/ -R 2.删除mqsql的配置文件 sudo rm /etc/mysql/ -R 3.自动卸载my ...

  7. Ubuntu 20.24 安装Postgresql 14

      1.运行环境 WSL+Ubuntu 20.04   2.安装Postgresql 进入Linux命令行,参照Postgresql官网安装指南 # Create the file repositor ...

  8. Ubuntu 安装和配置redis数据库

    Ubuntu 14.04下安装和配置redis数据库 小编现在在写一个分布式爬虫,要用到这个数据库,所以分享一下小编是如何安装和配置的,希望对大家有帮助. 工具/原料   Ubuntu 系统电脑一台 ...

  9. 在 Ubuntu 16.04 上安装 LEMP 环境之图文向导

    导读 LEMP 是个缩写,代表一组软件包(注解 ① L:Linux OS,E:Nginx 网络服务器,M:MySQL/MariaDB 数据库和 P:PHP 服务端动态编程语言),它被用来搭建动态的网络 ...

  10. Windows Azure上的Odoo(OpenERP)-1.创建Ubuntu虚拟机,安装PostgreSQL 数据库

    前提是您必须拥有Windows Azure的账号,如果没有的话,可以去Windows Azure 中国区网站申请免费试用账号.哈哈,我就是第一批申请的试用账号,感觉自己挺幸运的.申请的过程就不写了,请 ...

随机推荐

  1. ISIS 综合实验;BGP 实验

    目录 ISIS 综合实验 实验拓扑 实验需求 实验步骤 1.配置相应接口IP地址及环回口地址 2.配置 IS-IS,要求全网互通,R8的Loop X口暂不宣告 3. R1和R3直连,要求 R3 成为 ...

  2. LINQ检索使用

    我看网上对LINQ的讲解 自己整合了一下 是语言集成查询(Language Integrated Query)是一组用于C#和Visual Basic语言的扩展.能够允许编写C#或VB代码以查询数据相 ...

  3. 深入浅出synchronized的原理与源码

    深入浅出synchronized的原理与源码 1.java对象头关于锁的标识 1.对象头 // 32 bits: // -------- // hash:25 ------------>| ag ...

  4. BLOB-CLOB 处理成String (*)

    实体类中的写法: --实体类对应的类型为byte[] (clob为char[]). /* byte[] blob = commonService.getPersonImage(bean.getIdCa ...

  5. 前台vue发送json格式,后台srpeingboot不能自动处理解决办法

    使用HashMap解决,如下图

  6. SSIS向MySQL目标(Destination)写数据--Step By Step

    前言(废话) 最近的工作中涉及到SQLSERVER向MySQL的数据迁移同步,团队中理所当然准备用开发C#微服务接口的方式实现,我觉得这个路子曲折了,推荐SSIS的方式并自告奋勇接下了这个活.不过以前 ...

  7. AcWing 第87场周赛题解

    T1 移动棋子 算出数值为 \(1\) 的点离 \((3, 3)\) 的距离即可. #include <iostream> #include <cstring> #includ ...

  8. 【Python】从同步到异步多核:测试桩性能优化,加速应用的开发和验证

    测试工作中常用到的测试桩mock能力 在我们的测试工作过程中,可能会遇到多个项目并行开发的时候,后端服务还没有开发完成,或者我们需要压测某个服务,这个服务测在试环境的依赖组件(如 MQ) 无法支撑我们 ...

  9. Windows查询进程和杀死进程

    查询进程 查询进程占用的端口(通过端口查询) netstat -ano |findstr "端口号" 杀死进程 通过进程号查看所属进程名称 tasklist |findstr &q ...

  10. Java List集合根据某字段去重

    去重方法 单个字段为条件去重 /** * 单字段去重 * @param jackpotList1 新集合 * @param jackpotList 需要去重的集合 * @return */ priva ...