postgres --help
postgres数据库没有启动,用single就可以登录,启动了反而报错
[postgres@ogg2 ~]$ pg_ctl status
pg_ctl: no server running
[postgres@ogg2 ~]$ pg_ctl start
waiting for server to start....2022-10-27 10:25:08.191 CST [2916] LOG: listening on IPv4 address "0.0.0.0", port 5432
2022-10-27 10:25:08.191 CST [2916] LOG: listening on IPv6 address "::", port 5432
2022-10-27 10:25:08.192 CST [2916] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-10-27 10:25:08.193 CST [2916] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2022-10-27 10:25:08.236 CST [2916] LOG: redirecting log output to logging collector process
2022-10-27 10:25:08.236 CST [2916] HINT: Future log output will appear in directory "log".
done
server started
[postgres@ogg2 ~]$ postgres --single
2022-10-27 10:26:40.959 CST [2957] FATAL: lock file "postmaster.pid" already exists
2022-10-27 10:26:40.959 CST [2957] HINT: Is another postmaster (PID 2916) running in data directory "/data"?
[postgres@ogg2 ~]$ postgres --single -D /home/postgres
postgres: could not access the server configuration file "/home/postgres/postgresql.conf": No such file or directory
[postgres@ogg2 ~]$ pwd
/home/postgres
[postgres@ogg2 ~]$ postgres --single -D /data
2022-10-27 10:28:52.486 CST [2967] FATAL: lock file "postmaster.pid" already exists
2022-10-27 10:28:52.486 CST [2967] HINT: Is another postmaster (PID 2916) running in data directory "/data"?
postgres --single登录进去后psql命令无法使用;退出只能Ctrl+D
[root@ogg2 ~]# su - postgres
[postgres@ogg2 ~]$ which postgres
/usr/pgsql-11/bin/postgres
[postgres@ogg2 ~]$ postgres --help
postgres is the PostgreSQL server.
Options for single-user mode:
--single selects single-user mode (must be first argument)
DBNAME database name (defaults to user name)
-d 0-5 override debugging level
-E echo statement before execution
-j do not use newline as interactive query delimiter
-r FILENAME send stdout and stderr to given file
[postgres@ogg2 ~]$ postgres --single
PostgreSQL stand-alone backend 11.2
backend> select current_database();
1: current_database (typeid = 19, len = 64, typmod = -1, byval = f)
----
1: current_database = "postgres" (typeid = 19, len = 64, typmod = -1, byval = f)
----
backend> \d
2022-10-27 08:54:44.898 CST [2590] ERROR: syntax error at or near "\" at character 1
2022-10-27 08:54:44.898 CST [2590] STATEMENT: \d
backend> select count(*) from pg_tables;
1: count (typeid = 20, len = 8, typmod = -1, byval = t)
----
1: count = "74" (typeid = 20, len = 8, typmod = -1, byval = t)
----
backend> select count(*) from pg_class;
1: count (typeid = 20, len = 8, typmod = -1, byval = t)
----
1: count = "347" (typeid = 20, len = 8, typmod = -1, byval = t)
----
Oracle有个prelim的登录,数据库hang了无法连接时可使用;无法查询数据字典、v$视图和数据信息,均提示not logged on
sqlplus –prelim / as sysdba
[oracle@ogg1 ~]$ sqlplus -prelim / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Thu Oct 27 09:09:39 2022
Copyright (c) 1982, 2013, Oracle. All rights reserved.
SQL> select status from v$instance;
select status from v$instance
*
ERROR at line 1:
ORA-01012: not logged on
Process ID: 0
Session ID: 0 Serial number: 0
SQL> select count(*) from dba_tables;
select count(*) from dba_tables
*
ERROR at line 1:
ORA-01012: not logged on
Process ID: 0
Session ID: 0 Serial number: 0
SQL> select count(*) from test.test;
select count(*) from test.test
*
ERROR at line 1:
ORA-01012: not logged on
Process ID: 0
Session ID: 0 Serial number: 0
SQL> select count(*)from v$tablespace;
select count(*)from v$tablespace
*
ERROR at line 1:
ORA-01012: not logged on
Process ID: 0
Session ID: 0 Serial number: 0
oracle数据库没启动,-prelim也可以登录
[oracle@ogg1 ~]$ ps -ef | grep pmon
oracle 2598 2572 0 10:52 pts/0 00:00:00 grep pmon
[oracle@ogg1 ~]$ sqlplus -prelim / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Thu Oct 27 10:53:00 2022
Copyright (c) 1982, 2013, Oracle. All rights reserved.
SQL>