访问GitLab的PostgreSQL数据库

[root@localhost ~]# su - gitlab-psql //登陆用户

-sh-4.1$ psql -h /var/opt/gitlab/postgresql -d gitlabhq_production 连接到gitlabhq_production库

psql (9.2.18)
Type “help” for help.

gitlabhq_production=# \h 查看帮助命令

Available help:
ABORT CREATE FUNCTION DROP TABLE
ALTER AGGREGATE CREATE GROUP DROP TABLESPACE
ALTER COLLATION CREATE INDEX DROP TEXT SEARCH CONFIGURATION
ALTER CONVERSION CREATE LANGUAGE DROP TEXT SEARCH DICTIONARY
ALTER DATABASE CREATE OPERATOR DROP TEXT SEARCH PARSER
ALTER DEFAULT PRIVILEGES CREATE OPERATOR CLASS DROP TEXT SEARCH TEMPLATE
ALTER DOMAIN CREATE OPERATOR FAMILY DROP TRIGGER
ALTER EXTENSION CREATE ROLE DROP TYPE

……………………………………………………………………………………………………………………

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)

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 | award_emoji | table | gitlab
public | boards | table | gitlab
public | broadcast_messages | table | gitlab

……………………………………………………………………………………………………………………

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 |
message_html | text |
Indexes:
“abuse_reports_pkey” PRIMARY KEY, btree (id)

gitlabhq_production-# \di //查看索引
List of relations
Schema | Name | Type | Owner | Table

——–+—————————————————————–+——-+——–+——————————–

public | abuse_reports_pkey | index | gitlab | abuse_reports
public | appearances_pkey | index | gitlab | appearances
public | application_settings_pkey | index | gitlab | application_settings
public | audit_events_pkey | index | gitlab | audit_events
public | award_emoji_pkey | index | gitlab | award_emoji
public | boards_pkey | index | gitlab | boards
public | broadcast_messages_pkey | index | gitlab | broadcast_messages
public | chat_names_pkey | index | gitlab | chat_names
public | ci_application_settings_pkey | index | gitlab | ci_application_settings
public | ci_builds_pkey | index | gitlab | ci_builds
public | ci_commits_pkey | index | gitlab | ci_commits

………………………………………………………………………………………………………………………………………………

gitlabhq_production=# SELECT spcname FROM pg_tablespace; //查看所有表空间

spcname

pg_default
pg_global
(2 rows)

gitlabhq_production-# \q //退出psql
-sh-4.1$ exit //退出登录用户
logout

原文

重置密码

gitlab-rails console production
u=User.where(id:1).first
u.password = ‘secret_pass’
u.password_confirmation = ‘secret_pass’
u.save!

### 配置 GitLab 数据库设置教程 #### 安装 PostgreSQL 服务器 为了使 GitLab 使用独立的 PostgreSQL 数据库,需先安装并配置 PostgreSQL。对于大多数 Linux 发行版而言,可以通过包管理器完成此操作。 ```bash sudo apt-get update && sudo apt-get install postgresql postgresql-contrib -y ``` 上述命令适用于基于 Debian 的系统[^2]。 #### 创建数据库和用户 启动 PostgreSQL 并创建用于 GitLab 的专用数据库以及拥有适当权限的用户: ```sql sudo -u postgres psql CREATE DATABASE gitlabhq_production; CREATE USER git WITH PASSWORD 'your_password'; GRANT ALL PRIVILEGES ON DATABASE gitlabhq_production TO git; \q ``` 这段 SQL 命令序列完成了新用户的建立及其对特定数据库访问权授予的工作[^3]。 #### 修改 GitLab 配置文件 编辑 `/etc/gitlab/gitlab.rb` 文件来指定外部 PostgreSQL 实例的位置和其他必要参数。例如: ```ruby external_url 'http://gitlab.example.com' postgresql['enable'] = false gitlab_rails['db_adapter'] = "postgresql" gitlab_rails['db_encoding'] = "unicode" gitlab_rails['db_database'] = "gitlabhq_production" gitlab_rails['db_pool'] = 10 gitlab_rails['db_username'] = "git" gitlab_rails['db_password'] = "your_password" gitlab_rails['db_host'] = "/var/opt/gitlab/postgresql" gitlab_rails['db_socket'] = nil ``` 以上 Ruby 代码片段展示了如何调整 `gitlab.rb` 中有关数据库的部分以适应自定义设置的需求[^1]。 #### 应用更改并重启服务 保存修改后的配置文件后,运行以下命令应用这些变更并将所有改动生效于当前实例上: ```bash sudo gitlab-ctl reconfigure sudo systemctl restart gitlab-runsvdir.service ``` 这组 shell 指令确保了最新的配置能够被正确加载,并且整个 GitLab 系统得以重新初始化以便识别新的设定值[^4]。 #### 备份与恢复注意事项 当涉及到数据库迁移或升级时,务必采用与目标环境相匹配版本的工具来进行数据导出导入工作,以免引起兼容性问题而导致错误发生[^5]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值