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. 一次 SSH 攻击与处理小记

    这是我在简书看到的一个作者经历,结合小编自己的一些实践,抛砖引玉,给大家分享一下. 有段时间发现集群异常卡顿.担心的事情终于发生了,使用命令 lastb 查看了一下,我的天呢,好多未知的 IP,我随便 ...

  2. vulnhub_jangow

    来源 vulnhub:https://www.vulnhub.com/entry/jangow-101,754/ 描述 难度:简单 这在 VirtualBox 而不是 VMware 上效果更好 我这里 ...

  3. 【技术积累】Java中的JVM【一】

    什么是JVM JVM英文全称为Java Virtual Machine,中文意为Java虚拟机.JVM是一种能够执行Java语言编写的程序的虚拟机器,它首次作为Java语言的一部分,后来又被移植到了许 ...

  4. .NET周报 【6月第1期 2023-06-04】

    专题 - NanoFramework项目案例 如果有时间,我会在周报中加入一些专题和项目案例的分享,本周就是讨论.NET NanoFramework项目案例的专题,在讨论 NanoFramework ...

  5. 基于ChatGPT函数调用来实现C#本地函数逻辑链式调用助力大模型落地

    6 月 13 日 OpenAI 官网突然发布了重磅的 ChatGPT 更新,我相信大家都看到了 ,除了调用降本和增加更长的上下文版本外,开发者们最关心的应该还是新的函数调用能力.通过这项能力模型在需要 ...

  6. 一致性hash算法原理及实践

    大家好,我是蓝胖子,想起之前学算法的时候,常常只知表面,不得精髓,这个算法到底有哪些应用场景,如何应用在工作中,后来随着工作的深入,一些不懂的问题才慢慢被抽丝剥茧分解出来. 今天我们就来看看工作和面试 ...

  7. 分布式多协议接入网关FluxMQ-2.0功能说明

    FluxMQ-2.0版本更新内容 前言 FLuxMQ是一款基于java开发,支持无限设备连接的云原生分布式物联网接入平台.FluxMQ基于Netty开发,底层采用Reactor3反应堆模型,具备低延迟 ...

  8. 2021-7-6 vue音乐播放器

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script sr ...

  9. 2021-6-16 TcpIp

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  10. Pandas:删除最后一行

    解决方案 代码 效果展示 完整代码 import pandas as pd import numpy as np df = pd.DataFrame(np.arange(12).reshape(3,4 ...