打开GitLab+PostgreSql数据库

2020-10-23 07:09:03   LINUX

  Linux   GitLab  

一、第一步查看GitLab数据库配置

cat+/var/opt/gitlab/gitlab-rails/etc/database.yml

[root@VM_8_132_centos ~]# cat /var/opt/gitlab/gitlab-rails/etc/database.yml
# This file is managed by gitlab-ctl. Manual changes will be
# erased! To change the contents below, edit /etc/gitlab/gitlab.rb
# and run `sudo gitlab-ctl reconfigure`.

production:
  adapter: postgresql
  encoding: unicode
  collation:
  database: gitlabhq_production
  pool: 10
  username: 'gitlab'
  password:
  host: '/var/opt/gitlab/postgresql'
  port: 5432
  socket:
  sslmode:
  sslrootcert:
  sslca:

二、查看GitLab+数据库用户下一步登录使用

cat+/etc/passwd

       

[root@VM_8_132_centos ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
libstoragemgmt:x:998:997:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
chrony:x:997:995::/var/lib/chrony:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
syslog:x:996:994::/home/syslog:/bin/false
www:x:1000:1000::/home/www:/sbin/nologin
redis:x:1001:1001::/home/redis:/sbin/nologin
gitlab-www:x:995:991::/var/opt/gitlab/nginx:/bin/false
git:x:994:990::/var/opt/gitlab:/bin/sh
gitlab-redis:x:993:989::/var/opt/gitlab/redis:/bin/nologin
gitlab-psql:x:992:988::/var/opt/gitlab/postgresql:/bin/sh         //这个是gitlab登录用户
mysql:x:1002:1002::/home/mysql:/sbin/nologin


   

三、登录GitLab用户

su gitlab-psql

[root@VM_8_132_centos ~]# su gitlab-psql         //登录gitlab-psql用户
sh-4.2$ cd /opt/gitlab/embedded/bin/                 //没有设置环境变量的要切换到psql目录下,要不然找不到命令的
sh-4.2$ ./psql -h /var/opt/gitlab/postgresql -d gitlabhq_production    //这一步直接登录数据库
psql (9.2.16)
Type "help" for help.


四、接下来就可以进行psql的操作了

1.             \l   查询数据库

gitlabhq_production=# \l
                                             List of databases
        Name         |    Owner    | Encoding |   Collate   |    Ctype    |        Access privileges        
---------------------+-------------+----------+-------------+-------------+---------------------------------
 gitlabhq_production | gitlab      | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 postgres            | gitlab-psql | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 template0           | gitlab-psql | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/"gitlab-psql"               +
                     |             |          |             |             | "gitlab-psql"=CTc/"gitlab-psql"
 template1           | gitlab-psql | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/"gitlab-psql"               +
                     |             |          |             |             | "gitlab-psql"=CTc/"gitlab-psql"
(4 rows)

2.       \dt  查看夺标

gitlabhq_production-# \dt
                 List of relations
 Schema |          Name           | Type  | Owner  
--------+-------------------------+-------+--------
 public | abuse_reports           | table | gitlab
 public | appearances             | table | gitlab
 public | application_settings    | table | gitlab
 public | audit_events            | table | gitlab
 public | broadcast_messages      | table | gitlab
 public | ci_application_settings | table | gitlab
更多.....


3.     \d table 查看单标

gitlabhq_production-# \d abuse_reports
                                      Table "public.abuse_reports"
   Column    |            Type             |                         Modifiers                          
-------------+-----------------------------+------------------------------------------------------------
 id          | integer                     | not null default nextval('abuse_reports_id_seq'::regclass)
 reporter_id | integer                     |
 user_id     | integer                     |
 message     | text                        |
 created_at  | timestamp without time zone |
 updated_at  | timestamp without time zone |
Indexes:
    "abuse_reports_pkey" PRIMARY KEY, btree (id)



4.   \q  退出psql