openGauss 官网  
openGauss 下载地址 

支持的操作系统
● ARM:
  ● openEuler 20.03LTS(推荐采用此操作系统
  ● 麒麟V10
  ● Asianux 7.5
● X86:
  ● openEuler 20.03LTS
  ● CentOS 7.6
  ● Asianux 7.6

准备软硬件安装环境
# Step 1: 新建用户组、用户

groupadd dbgroup
useradd -g dbgroup omm
passwd omm
新密码:abcd@123456

# Step 2: 创建文件夹

mkdir -p /opt/software/openGauss
chown 755 -R /opt/software
chown -R omm /opt/software/openGauss

# Step 3: 下载安装包
下载地址:https://opengauss.org/zh/download
下载【openGauss_3.1.0 极简版】
把下载文件【openGauss-3.1.0-CentOS-64bit.tar.bz2】拷贝到【/opt/software/openGauss】目录

# Step 4: 关闭防火墙

systemctl disable firewalld.service
systemctl stop firewalld.service

# Step 5: 查看python版本

python -V

# Step 6: 关闭 selinux,目前仅支持在防火墙关闭的状态下进行安装

# 将 SELINUX=enforcing 改为 SELINUX=disabled
vim /etc/selinux/config
SELINUX=disabled

# Step 7: 关闭HISTORY记录

vim /etc/profile
HISTSIZE=0
source /etc/profile

# Step 8: 将交换内存关闭

swapoff -a

# Step 9: 关闭RemoveIPC【可以跳过】

vim  /etc/systemd/logind.conf
RemoveIPC=no

vim /usr/lib/systemd/system/systemd-logind.service
RemoveIPC=no

#重新加载配置参数
systemctl daemon-reload
systemctl restart systemd-logind

#检查修改是否生效
loginctl show-session | grep RemoveIPC
systemctl show systemd-logind | grep RemoveIPC

# Step 10: 设置字符集参数

cat /etc/profile
vim /etc/profile
LANG=en_US.UTF-8

# 重新加载 etc/profile
source /etc/profile

# Step 11: 重启操作系统

reboot

# Step 12: 切换omm用户

su omm

# Step 13: 解压安装包

cd /opt/software/openGauss
tar -jxf openGauss-3.1.0-CentOS-64bit.tar.bz2 -C /opt/software/openGauss
ls -lb

# Step 14: 使用有root权限的用户执行命令

# 不执行,可能出现错误提示
# the maximum number of SEMMNI is not correct, the current SEMMNI is xxx. Please check it.
cat /etc/sysctl.conf
sysctl -w kernel.sem="250 85000 250 330" 

# Step 15: 一键式脚本安装,一定要切换到 omm 用户

# 跳转目录simpleInstall
cd /opt/software/openGauss/simpleInstall
ls -l

#执行install.sh脚本安装openGauss
sh install.sh -w Gauss$123456 ~/.bashrc

# 提示:Would you like to create a demo database (yes/no)? 
# 输入【yes】

#参数说明
-w:初始化数据库密码(gs_initdb指定),安全需要必须设置。
-p:指定的openGauss端口号,如不指定,默认为5432。
-h|–help:打印使用说明。
安装后,该数据库部署结点的名称为sgnode(gs_initdb指定)。

# 恭喜你,基本安装成功了
Load demoDB [school,finance] success.
[complete successfully]: You can start or stop the database server using:
    gs_ctl start|stop|restart -D $GAUSSHOME/data/single_node -Z single_node

# 说明
openGauss端口号默认为5432
默认生成名称为postgres的数据库
数据库目录安装路径/opt/software/openGauss/data/single_node,其中/opt/software/openGauss为解压包路径,data/single_node为新创建的数据库节点目录。

# 执行ps命令,查看进程是否正常
ps ux | grep gaussdb

# 提示如下,安装成功
omm       23246  1.3 17.5 2841700 678364 ?      Ssl  10:59   0:07 /opt/software/openGauss/bin/gaussdb -D /opt/software/openGauss/data/single_node
omm       79232  0.0  0.0 112724   984 pts/1    S+   11:08   0:00 grep --color=auto gaussdb

# 执行gs_ctl命令,查看进程是否正常,如果没有找到 gs_ctl
# 解决方式1:配置环境变量即可 export PATH=/opt/software/openGauss/bin:$PATH,如果缺失lib则配置LD_LIBRARY_PATH
# 解决方式2:
cd /opt/software/openGauss/bin
ll

#先切换到【root】用户,再切换到【omm】用户,再执行如下命令
gs_ctl query -D /opt/software/openGauss/data/single_node【ok】
gs_ctl query -D /opt/software/openGauss/data/single_node -Z single_node【ok】
/opt/software/openGauss/bin/gs_ctl query -D /opt/software/openGauss/data/single_node【ok】

#启动
gs_ctl start -D /opt/software/openGauss/data/single_node -Z single_node

#停止
gs_ctl stop -D /opt/software/openGauss/data/single_node -Z single_node

#重启
gs_ctl restart -D /opt/software/openGauss/data/single_node -Z single_node

# openGauss重启
gs_ctl restart -D /opt/software/openGauss/data/single_node

#查看数据库主节点的端口号
cat /opt/software/openGauss/data/single_node/postgresql.conf | grep port
cat /opt/software/openGauss/data/master/postgresql.conf |grep port
cat /opt/software/openGauss/data/slave/postgresql.conf |grep port

##########################################
#                         gsql 连接与使用方法                      #
##########################################
#查询所有的数据库,需要先切换omm用户,su omm

[omm@localhost /]$ gsql -d postgres -p 5432 -l【success,默认omm用户】

# Step 1: 连接数据库,链接数据库

[omm@localhost /]$ gsql -d postgres -p 5432
[omm@localhost /]$ gsql -d postgres -p 5432 -r
[omm@localhost /]$ gsql -d postgres -U omm -p 5432 【无须输入密码,Gauss$123456】
[omm@localhost /]$ gsql -d postgres -U jim -p 5432 -W Bigdata@123【success】
[omm@localhost /]$ gsql -d postgres -h localhost -U zhangsan -p 5432 -W Gauss123456$【success】
[omm@localhost /]$ gsql -d db_test -U zhangsan -p 5432 -W Gauss123456$【success】
[omm@localhost /]$ gsql -d db_test -h 192.168.176.131 -U zhangsan -p 5432 -W Gauss123456$【fail】

# 创建用户
# Step 2: 创建用户,注意加分号

     # 语法:create user 用户名 with password "密码";
openGauss=# create user zhangsan with password "Gauss123456$";
openGauss=# create user zhaoliu with password 'Gauss123456$'; 
openGauss=# CREATE USER lisi WITH PASSWORD 'Gauss123456$'; 
openGauss=# CREATE USER jim CREATEDB PASSWORD 'Gauss123456$';  #创建有“创建数据库”权限的用户,则需要加CREATEDB关键字。

# 将sysadmin权限授权给zhangsan,授权成功后,用户zhangsan会拥有sysadmin的所有权限
openGauss=# GRANT ALL PRIVILEGES TO zhangsan;

# Step 3: 查看数据库用户列表

openGauss=# select * from pg_user;

# 查看所有角色

openGauss=# select * from PG_ROLES;

# 删除数据库用户,注意加分号

openGauss=# drop user zhangsan cascade;
openGauss=# drop user lisi cascade;

# 创建数据库,并指定所有者owner,注意加分号

       语法:create database 数据库名 owner 用户名;
openGauss=# create database db_test owner zhangsan;
openGauss=# create database db_test owner lisi;
openGauss=# create database db_sc with tablespace = tpcds_local;

# 删除数据库,注意加分号

       语法:drop database 数据库名;
openGauss=# drop database db_test;

# 创建表 

# 语法
CREATE TABLE warehouse_t0
(
    W_WAREHOUSE_NAME VARCHAR(20) ,
    W_ZIP CHAR(10)
);

openGauss=# \c db_test;

db_test=# CREATE TABLE warehouse_t1 (W_WAREHOUSE_NAME VARCHAR(20),W_ZIP CHAR(10));
db_test=# CREATE TABLE warehouse_t2 (W_WAREHOUSE_NAME VARCHAR(20),W_ZIP CHAR(10));
db_test=# CREATE TABLE warehouse_t3 (W_WAREHOUSE_NAME VARCHAR(20),W_ZIP CHAR(10));
db_test=# CREATE TABLE warehouse_t4 (W_WAREHOUSE_NAME VARCHAR(20));
db_test=# CREATE TABLE warehouse_t0
db_test-# (
db_test(#   W_WAREHOUSE_NAME VARCHAR(20) ,
db_test(#   W_ZIP CHAR(10)
db_test(# );

db_test=#  \dt;

# Step 4: 查看对象

openGauss=# \l            #查看数据库
openGauss=# \c school     #查看数据库
openGauss=# \dt           #查看数据库所有表名
openGauss=# \d student    #查看表结构
openGauss=# \d+ student   #查看表结构

# 使用[【\c + 数据库名】进入已存在数据库

openGauss=# \c school

# Step 5: 退出

openGauss=# \du

# 修改密码

# 将用户jim的登录密码由Bigdata@123修改为Abcd@123。
postgres=# ALTER USER 用户名 IDENTIFIED BY '新密码' REPLACE '旧密码';
postgres=# ALTER USER lisi IDENTIFIED BY 'Gauss123456$' REPLACE 'Gauss123456';
postgres=# ALTER USER jim IDENTIFIED BY 'Abcd@123' REPLACE 'Bigdata@123';
alter user <用户名> identified by '密码';

#切换用户

postgres=# \c 用户名

#退出数据库

postgres=# \q

# 插入 school 数据库 student 表数据,注意加分号

school=# insert into student() values();

# 查询 school 数据库 student 表数据,注意加分号

school=# select * from student;
school=# select * from student where std_name like '%张%';

# 删除 school 数据库 student 表数据,注意加分号

school=# DELETE FROM student where std_id = 100000;

# 删除 school 数据库 student 表数据,注意加分号

school=# DROP TABLE student;

# 配置外网访问
# 配置远程连接
# 配置允许远程连接,切换omm用户,su - omm

# Step 1: 文件 pg_hba.conf 修改
vim /opt/software/openGauss/data/single_node/pg_hba.conf
# 允许所有网段连接 在IPv4 local connections下添加
host  all    all    0.0.0.0/0    sha256
host  all    all    0.0.0.0/0    md5

# Step 2: 重新加载 gs_ctl 策略
su omm
cd /opt/software/openGauss/bin
gs_ctl reload -D /opt/software/openGauss/data/single_node

# Step 3: 文件 postgresql.conf 修改
vim /opt/software/openGauss/data/single_node/postgresql.conf
# 输入【/】搜索 listen_addresses 变量,将前面#去掉
listen_addresses = '*'
# 输入【/】搜索 password_encryption_type 变量,将前面#去掉
password_encryption_type  = 1

# Step 4: 重启数据库
su omm
cd /opt/software/openGauss/bin
gs_ctl restart -D  /opt/software/openGauss/data/single_node

##########################################
#                               DataStudio                               #
##########################################
# 使用 DataStudio 客户端连接 openGauss
远程连接主机地址:192.168.159.130
远程连接端口号:5432
数据库:postgres
用户名:lisi
密码:Gauss123456$
##########################################
#                                    .NET                                   #
##########################################
C# 采用 Npgsql 访问openGauss,因为 Npgsql 不支持 sha256 加密,所以将服务器端的认证加密更改为md5,如果改成MD5加密,Data Studio管理工具无法连接。首先设置 pg_hba.conf 和 postgresql.conf 文件,修改 postgresql.conf 文件,将 password_encryption_type 修改为1,同时支持 sha256 和 md5,然后修改数据库用户密码,这样密码才会存储为 sha256 和 md5 加密的字符串。

# Step 2: 修改配置文件
vim /opt/software/openGauss/data/single_node/postgresql.conf
# 输入【/】搜索 password_encryption_type 变量,将前面#去掉
password_encryption_type  = 1

# Step 3: 修改数据库用户密码
postgres=# ALTER USER 用户名 IDENTIFIED BY '新密码' REPLACE '旧密码';
postgres=# ALTER USER lisi IDENTIFIED BY 'Abcd1234@' REPLACE 'Abcd1234$';

##########################################
#                                常见问题                                 #
##########################################
42501: permission denied for relation student DETAIL: Detail redacted as it may contain sensitive data. Specify 'Include Error Detail' in the connection string to include this information."
*
*
*

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐