需求
需要查看gitlab用户的id
方法一
通过页面api查询
http://10.18.13.100:10080/api/v4/users?username=test101
方法二
进入gitlab数据库查询,gitlab是使用docker部署的,所以需要进入容器操作
root@10-18-13-100:~# docker ps | grep gitlab
9178130d2c2a 10.253.127.117:8080/gitlab/gitlab-ce:10.5.2-ce.0 "/.r/r /assets/wra..." 2 months ago Up 2 months (healthy) r-gitlab-gitlab-server-1-ca83b62b
root@10-18-13-100:~#
root@10-18-13-100:~#
root@10-18-13-100:~# docker exec -it 9178 bash
root@gitlab-gitlab-server-1:/#
操作数据库
root@gitlab-gitlab-server-1:/# gitlab-rails dbconsole
psql (9.6.5)
Type "help" for help.
## 列出数据库
gitlabhq_production=> \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
---------------------+-------------+----------+---------+---------+---------------------------------
gitlabhq_production | gitlab | UTF8 | C.UTF-8 | C.UTF-8 |
postgres | gitlab-psql | UTF8 | C.UTF-8 | C.UTF-8 |
template0 | gitlab-psql | UTF8 | C.UTF-8 | C.UTF-8 | =c/"gitlab-psql" +
| | | | | "gitlab-psql"=CTc/"gitlab-psql"
template1 | gitlab-psql | UTF8 | C.UTF-8 | C.UTF-8 | =c/"gitlab-psql" +
| | | | | "gitlab-psql"=CTc/"gitlab-psql"
(4 rows)
gitlabhq_production=>
## 连接数据库
gitlabhq_production=> \c gitlabhq_production
You are now connected to database "gitlabhq_production" as user "gitlab".
gitlabhq_production=>
## 查找账户id
gitlabhq_production=> select id from users where name = 'test101';
id
----
19
(1 row)