暂无图片
暂无图片
暂无图片
暂无图片
暂无图片
Halo DB 14 小白零基础系列1.docx
57
5页
0次
2024-02-03
免费下载
Halo DB 14 小白零基础系列(1-基本操作指南
前言:
Halo DB 使
一、Halo 数据库的基本操作:
注意:本章节下的所有命令,请在操作系统的 halo 用户下执行。
1、启动数据库:pg_ctl start
[halo@halodb1 ~]$ pg_ctl startwaiting for server to start....2024-01-02 13:26:53.655 CST [8669] LOG:
starting 羲和(Halo) 1.0.14.10 (231130) on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623
(Red Hat 4.8.5-44), 64-bit2024-01-02 13:26:53.655 CST [8669] LOG: listening on IPv6 address "::1", port
19212024-01-02 13:26:53.655 CST [8669] LOG: listening on IPv4 address "127.0.0.1", port 19212024-01-02
13:26:53.657 CST [8669] LOG: listening on Unix socket "/var/run/halo/.s.PGSQL.1921"2024-01-02
13:26:53.669 CST [8670] LOG: database system was shut down at 2024-01-02 13:26:50 CST2024-01-02
13:26:53.674 CST [8669] LOG: database system is ready to accept connectionsdoneserver started
2、查看数据库状态:pg_ctl status
[halo@halodb1 ~]$ pg_ctl status
pg_ctl: server is running (PID: 8669)
/u01/app/halo/product/dbms/14/bin/postgres
3、查看控制文件:pg_controldata
[halo@halodb1 ~]$ pg_controldatapg_control version number: 1300Catalog version number:
202107181Database system identifier: 7314545940227128703Database cluster state: in
productionpg_control last modified: Tue 02 Jan 2024 01:31:53 PM CSTLatest checkpoint location:
0/1E173D0Latest checkpoint's REDO location: 0/1E17398Latest checkpoint's REDO WAL file:
000000010000000000000001Latest checkpoint's TimeLineID: 1Latest checkpoint's PrevTimeLineID: 1Latest
checkpoint's full_page_writes: onLatest checkpoint's NextXID: 0:841Latest checkpoint's NextOID:
24984Latest checkpoint's NextMultiXactId: 1Latest checkpoint's NextMultiOffset: 0Latest checkpoint's
oldestXID: 732Latest checkpoint's oldestXID's DB: 1Latest checkpoint's oldestActiveXID: 841Latest
checkpoint's oldestMultiXid: 1Latest checkpoint's oldestMulti's DB: 14509Latest checkpoint's
oldestCommitTsXid:0Latest checkpoint's newestCommitTsXid:0Time of latest checkpoint: Tue 02 Jan 2024
01:31:53 PM CSTFake LSN counter for unlogged rels: 0/3E8Minimum recovery ending location: 0/0Min
recovery ending loc's timeline: 0Backup start location: 0/0Backup end location: 0/0End-of-backup
record required: nowal_level setting: replicawal_log_hints setting: offmax_connections setting:
100max_worker_processes setting: 8max_wal_senders setting: 10max_prepared_xacts setting:
0max_locks_per_xact setting: 64track_commit_timestamp setting: offMaximum data alignment: 8Database
block size: 8192Blocks per segment of large relation: 131072WAL block size: 8192Bytes per WAL
segment: 16777216Maximum length of identifiers: 64Maximum columns in an index: 32Maximum size of a
TOAST chunk: 1996Size of a large-object chunk: 2048Date/time type storage: 64-bit integersFloat8
argument passing: by valueData page checksum version: 0Mock authentication nonce:
aee41396502d5573e5df8cbddc6474f5f3a826776f5d7aae8df7af320b371cdf
4、关闭数据库:pg_ctl stop
[halo@halodb1 ~]$ pg_ctl stop
waiting for server to shut down....2024-01-02 13:43:31.236 CST [8669] LOG: received fast shutdown
request2024-01-02 13:43:31.247 CST [8669] LOG: aborting any active transactions2024-01-02
13:43:31.248 CST [8669] LOG: background worker "logical replication launcher" (PID 8676) exited
with exit code 12024-01-02 13:43:31.248 CST [8671] LOG: shutting down2024-01-02 13:43:31.261 CST
[8669] LOG: database system is shut down
doneserver stopped
5、登录数据库:psql -U halo halo0root
[halo@halodb1 ~]$ psql -U halo halo0root
psql (1.0.14.10 (231130))
Type "help" for help.
halo0root=# exit
二、psql 命令行常用操作:
便HaloDB PG
PG PG
1、列出数据库以及查看数据库编码:\l
[halo@halodb1 ~]$ psql
psql (1.0.14.10 (231130))
Type "help" for help.
halo0root=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+-------+----------+-------------+-------------+-------------------
halo0root | halo | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | halo | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/halo +
| | | | | halo=CTc/halo
template1 | halo | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/halo +
| | | | | halo=CTc/halo
testzz | halo | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
(4 rows)
halo0root=#
2、切换数据库:\c dbname username
halo0root=# \c testzz halo
You are now connected to database "testzz" as user "halo"
3、列出当前数据库所有的表:\dt
testzz=# \dt
List of relations
Schema | Name | Type | Owner
--------+----------+-------+-------
public | bonus | table | halo
public | dept | table | halo
public | emp | table | halo
public | salgrade | table | halo
(4 rows)
4、列出当前数据库所有的索引:\di
testzz=# \di
List of relations
Schema | Name | Type | Owner | Table
--------+---------+-------+-------+-------
public | pk_dept | index | halo | dept
public | pk_emp | index | halo | emp
(2 rows)
5 、列出 ROLE\du
testzz=# \du
List of roles
Role name | Attributes | Member of-----------
+------------------------------------------------------------+-----------
halo | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
6 列出 SCHEMA\dn
testzz=# \dnList of schemasName | Owner--------+-------public | halosys | halo(2 rows)
7、列出表空间:\db
testzz=# \dbList of tablespacesName | Owner | Location------------+-------+----------pg_default |
halo |pg_global | halo |(2 rows)
8、列出数据库扩展:\dx
halo0root=# \dxList of installed extensionsName | Version | Schema | Description----------
+---------+--------------------+------------------------------aux_init | 1.0 | information_schema |
Init Supplementary Extensionplpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language(2 rows)
9、列出当前数据库序列:\ds
halo0root=# \ds
Did not find any relations.
10、切换工作路径:\cd +文件路径
halo0root=# \cd /data/
11、查看当前会话连接信息:\conninfo
halo0root=# \conninfo
You are connected to database "halo0root" as user "halo" via socket in "/var/run/halo" at port
"1921".
12、显示和关闭 SQL 执行时间:\timing
testzz=# \timingTiming is on.testzz=# select * from emp;empno | ename | job | mgr | hiredate | sal | comm
| deptno-------+--------+-----------+------+------------+------+------+--------7369 | SMITH | CLERK |
7902 | 1980-12-17 | 800 | | 207499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600 | 300 | 307521 | WARD |
SALESMAN | 7698 | 1981-02-22 | 1250 | 500 | 307566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975 | | 207654
| MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250 | 1400 | 307698 | BLAKE | MANAGER | 7839 | 1981-05-01 |
2850 | | 307782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450 | | 107839 | KING | PRESIDENT | | 1981-11-17 |
5000 | | 107844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500 | 0 | 307900 | JAMES | CLERK | 7698 | 1981-
12-03 | 950 | | 307902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000 | | 207934 | MILLER | CLERK | 7782 |
1982-01-23 | 1300 | | 10(12 rows)
Time: 0.387 mstestzz=# \timing offTiming is off.testzz=# select * from emp;empno | ename | job | mgr |
hiredate | sal | comm | deptno-------+--------+-----------+------+------------+------+------+--------
7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800 | | 207499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600 |
300 | 307521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250 | 500 | 307566 | JONES | MANAGER | 7839 | 1981-
04-02 | 2975 | | 207654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250 | 1400 | 307698 | BLAKE | MANAGER |
7839 | 1981-05-01 | 2850 | | 307782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450 | | 107839 | KING |
of 5
免费下载
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文档的来源(墨天轮),文档链接,文档作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

关注
最新上传
暂无内容,敬请期待...
下载排行榜
Top250 周榜 月榜