当前位置:网站首页>PostgreSQL DBA快速入门-通过源码编译安装
PostgreSQL DBA快速入门-通过源码编译安装
2022-06-24 08:36:00 【post_yuan】
本文介绍通过PostgreSQL官方源码安装包编译安装的方式来快速上手PostgreSQL数据库。
前提条件
- 安装gmake,通过gmake -v查看
- 安装gcc,通过which gcc查看
- 安装tar,通过tar --help查看
- 安装GNU readline library,支持上下键、回退键等,通过rpm -qa | grep readline查看
- 安装Zlib compression library,用于压缩功能
创建用户
- id postgres -查看是否有postgres用户
- groupadd postgres -添加postgres组
- useradd -g postgres postgres -添加postgres用户
- passwd postgres -修改postgres密码
- mkdir -p /data/postgres/13.2/ -创建数据库目录
- chown -R postgres:postgres /data/ -修改数据库目录权限
安装并启动数据库
- su – postgres -切换postgres用户
- wget xxx.tar.gz -下载源码包
- tar -xzvf xxx.tar.gz -解压
- cd postgresql-13.2 -切换目录
- ./configure –preifx=/data/postgres/13.2/ -执行configure
- gmake world -执行gmake
- gmake install-world -执行gmake install
- /data/postgres/13.2/bin/initdb -d /data/postgres/13.2/data -初始化数据库
- /data/postgres/13.2/pg_ctl -D /data/postgres/13.2/data -l logfile start -启动数据库
修改环境变量
目的是为了不需要指定可执行文件(如psql、pg_ctl等)的绝对路径
- 修改postgres用户的~/.bash_profile,也可以直接修改~/.bashrc
PATH=xxx:/data/postgres/13.2/bin
PGDATA=/data/postgres/13.2/data
export PATH
export PGDATA - source ~/.bashrc
- 执行psql验证环境变量修改生效
修改数据库配置
在/data/postgres/13.2/data/pg_hba.conf中,添加下面行:
host all all 0.0.0.0/0 md5
以上表示对于所有使用IPV4的客户端机器,允许通过任意IP,通过任意用户可以发起对数据库的访问,但必须要提供数据库用户密码,认证方式为通过MD5加密认证。在/data/postgres/13.2/data/data/postgresql.conf中,修改
#listen_addresses=’localhost’为listen_addresses=’*’
需要重启
pg_ctl restart -m fast
表示允许任意客户端访问
如何启停数据库
- ps -ef | grep postges -检查数据库是否运行
- pg_ctl stop -m fast -停止数据库
- pg_ctl start -D /data/postgres/13/2/data -l ~/startup.log -启动数据库
- pg_ctl status -检查数据库状态
熟悉psql命令行工具
which psql
psql --help
psql -h localhost -p 5432 -d postgres -U postgres
\c -查看哪个用户连接哪个数据库
\d –查看表
\d <tablename> -查看表结构
\i ext.sql -执行一个文件,相当于Oracle中的@
\h -查看所有命令
\h create table -查看create table的帮助文档
select version(); -查看版本
\l -查看所有数据库信息
\l+ -查看数据库信息及大小信息
select pg_postmaster_start_time();
\du -查看用户信息
\dt+ -查看表大小
\di+ -查看索引信息
\dv -查看视图
\df -查看函数
边栏推荐
- Framework tool class obtained by chance for self use
- 零基础自学SQL课程 | 子查询
- Reasons for the failure of digital transformation and the way to success
- Cmake命令之target_compile_options
- Talking about the knowledge of digital transformation
- Directly applicable go coding specification
- e的lnx为什么等于x
- Some common pitfalls in getting started with jupyter:
- Servlet fast foundation building
- Tools
猜你喜欢

活动报名|Apache Pulsar x KubeSphere 在线 Meetup 火热报名中

Zero foundation self-study SQL course | having clause

Servlet快速筑基

Support vector machine (SVC, nusvc, linearsvc)

Handling method of Oracle data file header SCN inconsistency

二十、处理器调度(RR时间片轮转,MLFQ多级反馈队列,CFS完全公平调度器,优先级翻转;多处理器调度)

tp5 使用post接收数组数据时报variable type error: array错误的解决方法

Oracle 12c升级至19c后ORA-28000错误

零基础自学SQL课程 | 子查询

使用Live Chat促進業務銷售的驚人技巧
随机推荐
MYCAT read / write separation and MySQL master-slave synchronization
Conseils étonnants pour promouvoir les ventes d'entreprise avec le chat en direct
开源一款监控数据采集器,啥都能监控
P6117-[JOI 2019 Final]コイン集め【贪心】
Weekly recommended short video: talk about "meta universe" with a serious attitude
P6698-[balticoi 2020 day2] virus [AC automata, DP, SPFA]
LeetCode: 137. 只出现一次的数字 II
latex公式及表格识别
正则匹配邮箱
Endgame P.O.O
5分钟,客服聊天处理技巧,炉火纯青
Thinkphp5清除runtime下的cache缓存,temp缓存,log缓存
Cdga | how can we do well in data governance?
Depens:*** but it is not going to be installed
Leetcode -- linked list
每周推薦短視頻:談論“元宇宙”要有嚴肅認真的態度
LeetCode: 377. 组合总和 Ⅳ
P6698-[BalticOI 2020 Day2]病毒【AC自动机,dp,SPFA】
Target of cmake command_ compile_ options
深入解析 Apache BookKeeper 系列:第三篇——读取原理