1.登陆gitlab的安装服务查看配置文件

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

production:
adapter: postgresql
encoding: unicode
collation:
database: gitlabhq_production //数据库名
pool:
username: 'gitlab' //用户名
password:
host: '/var/opt/gitlab/postgresql' //主机
port:
socket:
sslmode:
sslrootcert:
sslca:

查看/etc/passwd文件里边gitlab对应的系统用户

[root@localhost ~]# cat /etc/passwd
root:x:::root:/root:/bin/bash
gitlab-www:x::::/var/opt/gitlab/nginx:/bin/false
git:x::::/var/opt/gitlab:/bin/sh
gitlab-redis:x::::/var/opt/gitlab/redis:/bin/false
gitlab-psql:x::::/var/opt/gitlab/postgresql:/bin/sh //gitlab的postgresql用户

2.根据上面的配置信息登陆postgresql数据库

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

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

psql (9.2.)
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- | en_US.UTF- |
postgres | gitlab-psql | UTF8 | en_US.UTF- | en_US.UTF- |
template0 | gitlab-psql | UTF8 | en_US.UTF- | en_US.UTF- | =c/"gitlab-psql" +
| | | | | "gitlab-psql"=CTc/"gitlab-psql"
template1 | gitlab-psql | UTF8 | en_US.UTF- | en_US.UTF- | =c/"gitlab-psql" +
| | | | | "gitlab-psql"=CTc/"gitlab-psql"
( rows)

gitlabhq_production-# \c gitlabhq_production //进入gitlabhq_production库 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
( rows) gitlabhq_production-# \q //退出psql
-sh-4.1$ exit //退出登录用户
logout

批量替换某个表字段的字符串

update tableA set field=replace(field,'value1','value2')

导出整个库:

pg_dump -h 127.0.0.1 -U testuser test >test.sql

导入整个库

psql -U testuser test < test.sql

注意:这里的testuser是postgres用户,test是数据库名称,而且,testuser需要有test的权限

访问GitLab的PostgreSQL数据库,查询、修改、替换等操作的更多相关文章

  1. 访问GitLab的PostgreSQL数据库-(3)

    1.登陆gitlab的安装服务查看配置文件 cat /var/opt/gitlab/gitlab-rails/etc/database.yml production: adapter: postgre ...

  2. 访问GitLab的PostgreSQL数据库

    1.登陆gitlab的安装服务查看配置文件 cat /var/opt/gitlab/gitlab-rails/etc/database.yml production: adapter: postgre ...

  3. 怎样从外网访问内网PostgreSQL数据库?

    本地安装了一个PostgreSQL数据库,只能在局域网内访问到,怎样从外网也能访问到本地的PostgreSQL数据库呢?本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动PostgreSQ ...

  4. 更改配置:远程访问gitlab的postgresql数据库

    作为这篇文章的补充: 将gitlab中的postgresql数据库开通远程访问 https://www.cnblogs.com/andy9468/p/10609682.html 替代(二)中的2.3. ...

  5. 【.NET 6】使用EF Core 访问Oracle+Mysql+PostgreSQL并进行简单增改操作与性能比较

     前言 唠嗑一下.都在说去O或者开源,但是对于数据库选型来说,很多人却存在着误区.例如,去O,狭义上讲,是去Oracle数据库.但是从广义上来说,是去Oracle公司产品或者具有漂亮国垄断地位和需要商 ...

  6. yii2.0数据库查询修改等方法

    yii2.0学习有一段时间了,给大家分享一下一些简单的查询等如何操作. 查询:(这里最前面的Test是引用的模型名) Test::find()->all();    此方法返回所有数据: Tes ...

  7. postgresql数据库查询慢SQL

    --查询总耗时最长SQLselect * from pg_stat_statements order by total_time desc;--查询平均耗时最长SQLselect * from pg_ ...

  8. PostgreSQL数据库查询最近几天的数据

    pgsql语法类似mysql  ,下面总结几个pgsql工作会用到的求时间的语句 1.当前时间向前推一天\ SELECT current_timestamp - interval '1 day' 例: ...

  9. Python全栈day21(作业针对一个文件进行查询修改删除的操作练习)

    需求,有一个配置文件test.conf内容如下 backend www1 server 1 server 2 backend www2 server 3 server 4 add [{'backend ...

随机推荐

  1. What’s new for Spark SQL in Apache Spark 1.3(中英双语)

    文章标题 What’s new for Spark SQL in Apache Spark 1.3 作者介绍 Michael Armbrust 文章正文 The Apache Spark 1.3 re ...

  2. 解决Eclipse中“诡异”的错误:找不到或无法加载主类

    记录下来遇到的(问题,解决方法),是更有效的解决问题的方式.(原谅我领悟的太晚与懒,从此用更有意义的方法,做一个更有意义的人) 因为遇到了多次,参考同一个方法,原文连接:https://blog.cs ...

  3. ETF计划Q&A

    ETF计划Q&A 2018-07-16 参考:详解ETF计划.ETF计划Q&A(2017版) 目录 问1:ETF计划是什么?问2:ETF计划适合什么人参加?问3:我想参考你的计划,但告 ...

  4. IFRAME练习 各种调用

    parent.html. <html> <head> <script type="text/javascript"> function say( ...

  5. 使用nginx搭建rtmp服务器

    一.软件需求 1.nginx源码包  下载地址:http://nginx.org/.笔者下载的是1.10.3. 2.pcre源码包.这是一个正则表达式库.nginx会用到这个开源库来做正则匹配.很多软 ...

  6. yml 后面的配置覆盖前面的

    事情是这样的: a: b: c: tomcat d: hoho # 中间还隔了好多 a: b: c: tomcat 这种情况下,后面的配置会覆盖前面的所有配置,即 a.d = hoho 也会被覆盖 y ...

  7. Build GMP on 64bit Windows

    1.MSYS2 环境搭建 1.1.安装 msys2 的主页地址: http://www.msys2.org/ 下载32位或64位,我这里 下载了64位 msys2-x86_64-20161025.ex ...

  8. 蜻蜓特派员 Windows XP SP3 纯净终结版

    蜻蜓特派员Windows XP SP3 纯净安装版 终结版,系统纯净无广告.无插件,网卡等驱动和运行库齐全,安全更新补丁全网最新!微软停止了 Windows XP 的支持之后还是偶尔为 WinXP 提 ...

  9. git 同步远程已删除的分支和删除本地多余的分支

    使用git branch -a可以查看本地分支和远程分支情况 但远程分支(红色部分)删除后,发现本地并没有同步过来. 一. 同步本地的远程分支 查看本地分支和追踪情况: git remote show ...

  10. 大整数加减运算的C语言实现

    目录 大整数加减运算的C语言实现 一. 问题提出 二. 代码实现 三. 效果验证 大整数加减运算的C语言实现 标签: 大整数加减 C 一. 问题提出 培训老师给出一个题目:用C语言实现一个大整数计算器 ...