1.配置数据库用户、目录

# useradd opgauss

# mkdir -p /opgauss/data/single_node

# chown opgauss.opgauss -R /opgauss/data/single_node

# chmod 775 -R /opgauss/


2.配置环境变量

# su - opgauss

$ vi .bash_profile  

# .bash_profile

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

. ~/.bashrc

fi


# User specific environment and startup programs

export GS_CLUSTER_NAME=dbCluster

export GAUSSHOME=/opt/openGauss/3.0.0

export LD_LIBRARY_PATH=$GAUSSHOME/lib

export PATH=$GAUSSHOME/bin:$PATH:$HOME/.local/bin:$HOME/bin


$ source .bash_profile

$ gs_initdb --version

gs_initdb (openGauss) 9.2.4


3.初始化数据库


$ export password=opgauss@123   # 密码长度大于8

$ gs_initdb -w $password -D /opgauss/data/single_node --nodename "sgnode" --locale="en_US.UTF-8"

The files belonging to this database system will be owned by user "opgauss".

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".


fixing permissions on existing directory /opgauss/data/single_node ... ok

creating subdirectories ... ok

selecting default max_connections ... 100

selecting default shared_buffers ... 32MB

creating configuration files ... ok

Begin init undo subsystem meta.

[INIT UNDO] Init undo subsystem meta successfully.

creating template1 database in /opgauss/data/single_node/base/1 ... 2022-04-03 11:35:48.071 [unknown] [unknown] localhost 140058547184128 0[0:0#0]  [BACKEND] WARNING:  macAddr is 12/702416382, sysidentifier is 797150/100584372, randomNum is 1981402036

ok

initializing pg_authid ... ok

setting password ... ok

initializing dependencies ... ok

loading PL/pgSQL server-side language ... ok

creating system views ... ok

creating performance views ... ok

loading system objects' descriptions ... ok

creating collations ... ok

creating conversions ... ok

creating dictionaries ... ok

setting privileges on built-in objects ... ok

initialize global configure for bucketmap length ... ok

creating information schema ... ok

loading foreign-data wrapper for distfs access ... ok

loading foreign-data wrapper for hdfs access ... ok

loading foreign-data wrapper for log access ... ok

loading hstore extension ... ok

loading security plugin ... ok

update system tables ... ok

creating snapshots catalog ... ok

vacuuming database template1 ... ok

copying template1 to template0 ... ok

copying template1 to postgres ... ok

freezing database template0 ... ok

freezing database template1 ... ok

freezing database postgres ... ok


WARNING: enabling "trust" authentication for local connections

You can change this by editing pg_hba.conf or using the option -A, or

--auth-local and --auth-host, the next time you run gs_initdb.


Success. You can now start the database server of single node using:


   gaussdb -D /opgauss/data/single_node --single_node

or

   gs_ctl start -D /opgauss/data/single_node -Z single_node -l logfile


$  


4.参数修改


listen_addresses = '*'


# This is used when logging to stderr:

logging_collector = on                  # Enable capturing of stderr and csvlog

                                       # into log files. Required to be on for

                                       # csvlogs.

                                       # (change requires restart)


# These are only used if logging_collector is on:

#log_directory = 'pg_log'               # directory where log files are written,

                                       # can be absolute or relative to PGDATA

log_filename = 'postgresql-%a.log'      # log file name pattern,

                                       # can include strftime() escapes

log_file_mode = 0600                    # creation mode for log files,

                                       # begin with 0 to use octal notation

log_truncate_on_rotation = on           # If on, an existing log file with the

                                       # same name as the new log file will be

                                       # truncated rather than appended to.

                                       # But such truncation only occurs on

                                       # time-driven rotation, not on restarts

                                       # or size-driven rotation.  Default is

                                       # off, meaning append to existing files

                                       # in all cases.

#log_rotation_age = 1d                  # Automatic rotation of logfiles will

                                       # happen after that time.  0 disables.

log_rotation_size = 0  


5.启动数据库

$ gs_ctl start -D /opgauss/data/single_node -Z single_node

[2022-04-03 11:39:21.649][76667][][gs_ctl]: gs_ctl started,datadir is /opgauss/data/single_node  

[2022-04-03 11:39:21.728][76667][][gs_ctl]: waiting for server to start...

.0 LOG:  [Alarm Module]can not read GAUSS_WARNING_TYPE env.


0 LOG:  [Alarm Module]Host Name: ogsdb01  


0 LOG:  [Alarm Module]Host IP: 192.168.43.113  


0 LOG:  [Alarm Module]Cluster Name: dbCluster  


0 LOG:  [Alarm Module]Invalid data in AlarmItem file! Read alarm English name failed! line: 57


0 WARNING:  failed to open feature control file, please check whether it exists: FileName=gaussdb.version, Errno=2, Errmessage=No such file or directory.

0 WARNING:  failed to parse feature control file: gaussdb.version.

0 WARNING:  Failed to load the product control file, so gaussdb cannot distinguish product version.

2022-04-03 11:39:21.994 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [BACKEND] LOG:  when starting as multi_standby mode, we couldn't support data replicaton.

gaussdb.state does not exist, and skipt setting since it is optional.2022-04-03 11:39:22.031 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [BACKEND] LOG:  [Alarm Module]can not read GAUSS_WARNING_TYPE env.


2022-04-03 11:39:22.031 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [BACKEND] LOG:  [Alarm Module]Host Name: ogsdb01  


2022-04-03 11:39:22.063 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [BACKEND] LOG:  [Alarm Module]Host IP: 192.168.43.113  


2022-04-03 11:39:22.063 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [BACKEND] LOG:  [Alarm Module]Cluster Name: dbCluster  


2022-04-03 11:39:22.064 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [BACKEND] LOG:  [Alarm Module]Invalid data in AlarmItem file! Read alarm English name failed! line: 57


2022-04-03 11:39:22.068 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [BACKEND] LOG:  loaded library "security_plugin"

2022-04-03 11:39:22.069 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [BACKEND] WARNING:  could not create any HA TCP/IP sockets

2022-04-03 11:39:22.069 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [BACKEND] WARNING:  could not create any HA TCP/IP sockets

2022-04-03 11:39:22.072 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [BACKEND] WARNING:  No explicit IP is configured for listen_addresses GUC.

2022-04-03 11:39:22.072 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [BACKEND] LOG:  InitNuma numaNodeNum: 1 numa_distribute_mode: none inheritThreadPool: 0.

2022-04-03 11:39:22.072 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [BACKEND] LOG:  reserved memory for backend threads is: 220 MB

2022-04-03 11:39:22.072 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [BACKEND] LOG:  reserved memory for WAL buffers is: 128 MB

2022-04-03 11:39:22.072 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [BACKEND] LOG:  Set max backend reserve memory is: 348 MB, max dynamic memory is: 11065 MB

2022-04-03 11:39:22.072 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [BACKEND] LOG:  shared memory 362 Mbytes, memory context 11413 Mbytes, max process memory 12288 Mbytes

2022-04-03 11:39:22.106 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [CACHE] LOG:  set data cache  size(402653184)

2022-04-03 11:39:22.126 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [CACHE] LOG:  set metadata cache  size(134217728)

2022-04-03 11:39:22.172 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [SEGMENT_PAGE] LOG:  Segment-page constants: DF_MAP_SIZE: 8156, DF_MAP_BIT_CNT: 65248, DF_MAP_GROUP_EXTENTS: 4175872, IPBLOCK_SIZE: 8168, EXTENTS_PER_IPBLOCK: 1021, IPBLOCK_GROUP_SIZE: 4090, BMT_HEADER_LEVEL0_TOTAL_PAGES: 8323072, BktMapEntryNumberPerBlock: 2038, BktMapBlockNumber: 25, BktBitMaxMapCnt: 512

2022-04-03 11:39:22.206 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [BACKEND] LOG:  gaussdb: fsync file "/opgauss/data/single_node/gaussdb.state.temp" success

2022-04-03 11:39:22.206 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [BACKEND] LOG:  create gaussdb state file success: db state(STARTING_STATE), server mode(Normal), connection index(1)

2022-04-03 11:39:22.357 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [BACKEND] LOG:  max_safe_fds = 979, usable_fds = 1000, already_open = 11

2022-04-03 11:39:22.360 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [BACKEND] LOG:  user configure file is not found, it will be created.

2022-04-03 11:39:22.365 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [BACKEND] LOG:  the configure file /opt/openGauss/3.0.0/etc/gscgroup_opgauss.cfg doesn't exist or the size of configure file has changed. Please create it by root user!

2022-04-03 11:39:22.365 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [BACKEND] LOG:  Failed to parse cgroup config file.

2022-04-03 11:39:22.396 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [EXECUTOR] WARNING:  Failed to obtain environment value $GAUSSLOG!

2022-04-03 11:39:22.396 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [EXECUTOR] DETAIL:  N/A

2022-04-03 11:39:22.396 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [EXECUTOR] CAUSE:  Incorrect environment value.

2022-04-03 11:39:22.396 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [EXECUTOR] ACTION:  Please refer to backend log for more details.

2022-04-03 11:39:22.397 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [EXECUTOR] WARNING:  Failed to obtain environment value $GAUSSLOG!

2022-04-03 11:39:22.397 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [EXECUTOR] DETAIL:  N/A

2022-04-03 11:39:22.397 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [EXECUTOR] CAUSE:  Incorrect environment value.

2022-04-03 11:39:22.397 [unknown] [unknown] localhost 140215847408128 0[0:0#0]  0 [EXECUTOR] ACTION:  Please refer to backend log for more details.


[2022-04-03 11:39:22.737][76667][][gs_ctl]:  done

[2022-04-03 11:39:22.737][76667][][gs_ctl]: server started (/opgauss/data/single_node)

$  


6.查询数据库状态

进程状态

$ ps ux | grep gaussdb

opgauss   76670  1.3  5.3 2873960 423904 ?      Ssl  11:39   0:03 /opt/openGauss/3.0.0/bin/gaussdb -D /opgauss/data/single_node

opgauss   76748  0.0  0.0 110480   908 pts/0    S+   11:43   0:00 grep --color=auto gaussdb

$  

$

数据库节点状态 

$ gs_ctl query -D /opgauss/data/single_node

[2022-04-03 11:43:40.774][76753][][gs_ctl]: gs_ctl query ,datadir is /opgauss/data/single_node  

HA state:            

local_role                     : Normal

static_connections             : 0

db_state                       : Normal

detail_information             : Normal


Senders info:        

No information  

Receiver info:      

No information  

$  


7. 登录数据库

$ gsql -d postgres

gsql ((openGauss 3.0.0 build ) compiled at 2022-04-03 10:47:11 commit 0 last mr  )

Non-SSL connection (SSL connection is recommended when requiring high-security)

Type "help" for help.

openGauss=# \l+

                                                                List of databases

  Name    |  Owner  | Encoding |   Collate   |    Ctype    |  Access privileges  | Size  | Tablespace |                Description                  

-----------+---------+----------+-------------+-------------+---------------------+-------+------------+--------------------------------------------

postgres  | opgauss | UTF8     | en_US.UTF-8 | en_US.UTF-8 |                     | 12 MB | pg_default | default administrative connection database

template0 | opgauss | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/opgauss         +| 12 MB | pg_default | default template for new databases

          |         |          |             |             | opgauss=CTc/opgauss |       |            |  

template1 | opgauss | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/opgauss         +| 12 MB | pg_default | unmodifiable empty database

          |         |          |             |             | opgauss=CTc/opgauss |       |            |  

(3 rows)

openGauss=# \du+

                                                                    List of roles

Role name |                                                    Attributes                                                    | Member of | Description  

-----------+------------------------------------------------------------------------------------------------------------------+-----------+-------------

opgauss   | Sysadmin, Create role, Create DB, Replication, Administer audit, Monitoradmin, Operatoradmin, Policyadmin, UseFT | {}        |  

openGauss=#  

openGauss=# \q