暂无图片
暂无图片
1
暂无图片
暂无图片
暂无图片

openGauss每日一练第 1 天 | 查看数据库状态及版本

原创 超越无限D 2022-11-24
1394

学习目标

学习从操作系统层面和使用openGauss工具查看数据库的状态、版本和数据文件目录。

课程学习

gs_ctl是openGauss提供的数据库服务控制工具,可以用来启停数据库服务和查询数据库状态。主要供openGauss管理模块调用。

gs_ctl工具由操作系统用户omm执行。可以执行:
启动、停止、重启openGauss节点。

root登陆进入web终端:由root用户切换到omm用户下

用户切换

root@modb:~# su - omm

1.从操作系统层面查看数据库进程和线程,判断数据库是否启动。

如下显示是已启动。

 omm@modb:~$ ps -ef|grep gauss
omm          1     0  0 10:12 ?        00:00:18 gaussdb
omm        723   698  0 11:19 pts/1    00:00:00 grep gauss

omm@modb:~$ ps -Tp 1
  PID  SPID TTY          TIME CMD
    1     1 ?        00:00:00 gaussdb
    1   287 ?        00:00:00 jemalloc_bg_thd
    1   293 ?        00:00:00 gaussdb
    1   294 ?        00:00:00 syslogger
    1   295 ?        00:00:00 jemalloc_bg_thd
    1   296 ?        00:00:00 alarm
    1   297 ?        00:00:00 reaper
    1   298 ?        00:00:00 jemalloc_bg_thd
    1   299 ?        00:00:00 jemalloc_bg_thd
    1   343 ?        00:00:00 checkpointer
    1   344 ?        00:00:00 Spbgwriter
    1   345 ?        00:00:00 pagewriter
    1   346 ?        00:00:03 pagewriter
    1   347 ?        00:00:00 pagewriter
    1   348 ?        00:00:00 pagewriter
    1   349 ?        00:00:00 pagewriter
    1   350 ?        00:00:00 WALwriter
    1   351 ?        00:00:00 WALwriteraux
    1   352 ?        00:00:00 AVClauncher
    1   353 ?        00:00:00 Jobscheduler
    1   354 ?        00:00:00 asyncundolaunch
    1   355 ?        00:00:00 globalstats
    1   356 ?        00:00:00 applylauncher
    1   357 ?        00:00:00 statscollector
    1   358 ?        00:00:02 percentworker
    1   359 ?        00:00:06 ashworker
    1   360 ?        00:00:02 TrackStmtWorker
    1   361 ?        00:00:00 auditor
    1   362 ?        00:00:00 2pccleaner
    1   364 ?        00:00:00 WLMworker
    1   363 ?        00:00:00 faultmonitor
    1   365 ?        00:00:00 WLMmonitor
    1   366 ?        00:00:00 WLMarbiter
    1   367 ?        00:00:00 undorecycler

2.使用gs_ctl工具查看数据库状态,判断数据库是否启动。

显示gs_ctl: server is running (PID: 1)则是已启动。

omm@modb:~$ gs_ctl status
[2022-11-24 11:20:57.350][729][][gs_ctl]: gs_ctl status,datadir is /var/lib/opengauss/data 
gs_ctl: server is running (PID: 1)
/usr/local/opengauss/bin/gaussdb

3.使用gs_ctl 查看数据文件的目录
查询如下:

omm@modb:~$ gs_ctl notify
[2022-11-24 11:21:31.928][737][][gs_ctl]: gs_ctl notify ,datadir is /var/lib/opengauss/data 
[2022-11-24 11:21:31.929][737][][gs_ctl]: the parameter of notify must be specified

4.从环境变量查看数据文件的目录

 grep -i PGDATA ~/.bashrc
omm@modb:~$ grep i PADATA ~/.bashrc
grep: PADATA: No such file or directory
/home/omm/.bashrc:# ~/.bashrc: executed by bash(1) for non-login shells.
/home/omm/.bashrc:# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
/home/omm/.bashrc:# If not running interactively, don't do anything
/home/omm/.bashrc:case $- in
/home/omm/.bashrc:    *i*) ;;
/home/omm/.bashrc:# don't put duplicate lines or lines starting with space in the history.
/home/omm/.bashrc:# See bash(1) for more options
/home/omm/.bashrc:HISTCONTROL=ignoreboth
/home/omm/.bashrc:# append to the history file, don't overwrite it
/home/omm/.bashrc:shopt -s histappend
/home/omm/.bashrc:# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
/home/omm/.bashrc:# check the window size after each command and, if necessary,
/home/omm/.bashrc:shopt -s checkwinsize
/home/omm/.bashrc:# If set, the pattern "**" used in a pathname expansion context will
/home/omm/.bashrc:# match all files and zero or more directories and subdirectories.
/home/omm/.bashrc:# make less more friendly for non-text input files, see lesspipe(1)
/home/omm/.bashrc:#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
/home/omm/.bashrc:# set variable identifying the chroot you work in (used in the prompt below)
/home/omm/.bashrc:if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
/home/omm/.bashrc:    debian_chroot=$(cat /etc/debian_chroot)
/home/omm/.bashrc:fi
/home/omm/.bashrc:case "$TERM" in
/home/omm/.bashrc:# uncomment for a colored prompt, if the terminal has the capability; turned
/home/omm/.bashrc:# off by default to not distract the user: the focus in a terminal window
/home/omm/.bashrc:if [ -n "$force_color_prompt" ]; then
/home/omm/.bashrc:    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
/home/omm/.bashrc:      # We have color support; assume it's compliant with Ecma-48
/home/omm/.bashrc:      # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
/home/omm/.bashrc:    fi/home/omm/.bashrc:    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
/home/omm/.bashrc:fi
/home/omm/.bashrc:# If this is an xterm set the title to user@host:dir
/home/omm/.bashrc:case "$TERM" in

/home/omm/.bashrc:fi
/home/omm/.bashrc:if [ "$color_prompt" = yes ]; then
/home/omm/.bashrc:    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

/home/omm/.bashrc:    #alias vdir='vdir --color=auto'
/home/omm/.bashrc:    #alias grep='grep --color=auto'
/home/omm/.bashrc:    #alias fgrep='fgrep --color=auto'
/home/omm/.bashrc:    #alias egrep='egrep --color=auto'
/home/omm/.bashrc:fi
/home/omm/.bashrc:# colored GCC warnings and errors
/home/omm/.bashrc:#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
/home/omm/.bashrc:# some more ls aliases
/home/omm/.bashrc:#alias ll='ls -l'
/home/omm/.bashrc:#alias la='ls -A'
/home/omm/.bashrc:#alias l='ls -CF'
/home/omm/.bashrc:# Alias definitions.
/home/omm/.bashrc:# You may want to put all your additions into a separate file like
/home/omm/.bashrc:# ~/.bash_aliases, instead of adding them here directly.
/home/omm/.bashrc:# See /usr/share/doc/bash-doc/examples in the bash-doc package.
/home/omm/.bashrc:if [ -f ~/.bash_aliases ]; then
/home/omm/.bashrc:    . ~/.bash_aliases
/home/omm/.bashrc:fi
/home/omm/.bashrc:# enable programmable completion features (you don't need to enable
/home/omm/.bashrc:# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
/home/omm/.bashrc:if ! shopt -oq posix; then
/home/omm/.bashrc:  if [ -f /usr/share/bash-completion/bash_completion ]; then
/home/omm/.bashrc:    . /usr/share/bash-completion/bash_completion
/home/omm/.bashrc:  elif [ -f /etc/bash_completion ]; then
/home/omm/.bashrc:    . /etc/bash_completion
/home/omm/.bashrc:  fi
/home/omm/.bashrc:fi
/home/omm/.bashrc:export PATH=/home/omm/.bashrc:    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
/home/omm/.bashrc:# enable color support of ls and also add handy aliases
/home/omm/.bashrc:if [ -x /usr/bin/dircolors ]; then
/home/omm/.bashrc:    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
/home/omm/.bashrc:    alias ls='ls --color=auto'
/home/omm/.bashrc:    #alias dir='dir --color=auto'$GAUSSHOME/bin:$PATH 
/home/omm/.bashrc:export LD_LIBRARY_PATH=$GAUSSHOME/lib:$LD_LIBRARY_PATH
/home/omm/.bashrc:export PGDATA=/var/lib/opengauss/data

5.在gsql中查看数据文件目录、数据库版本

从root切换到omm用户

root@modb:~# su - omm

登陆数据库

omm@modb:~$ gsql -r
gsql ((openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:12:00 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

omm=# 

查看数据目录

omm=# show data_directory;
     data_directory      
-------------------------
 /var/lib/opengauss/data
(1 row)

查看数据库版本

omm=# select version();
                                                                        version                                                                        
-------------------------------------------------------------------------------------------------------------------------------------------------------
 (openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:12:00 commit 0 last mr   on aarch64-unknown-linux-gnu, compiled by g++ (GCC) 7.3.0, 64-bit
(1 row)

通过今天openGauss的学习,让我了解了openGauss的操作环境和工具的相关使用,对数据库的版本、数据目录存储位置有了一个深入的了解,也学会了openGauss数据库查看的相关命令。

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论