启动 PostgreSQL 时出错:无法打开目录/不是目录

启动 PostgreSQL 时出错:无法打开目录/不是目录

今天,Ubuntu 20 中的 PostgreSQL 12 突然出现错误。在此之前,使用数据库(Odoo)的系统一直运行正常:

2022-08-25 00:50:04.580 UTC [34164] LOG:  starting PostgreSQL 12.11 (Ubuntu 12.11-0ubuntu0.20.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.4.0-1u>
2022-08-25 00:50:04.581 UTC [34164] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2022-08-25 00:50:04.581 UTC [34164] LOG:  listening on IPv6 address "::", port 5432
2022-08-25 00:50:04.588 UTC [34164] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-08-25 00:50:04.629 UTC [34164] LOG:  could not open directory "pg_tblspc/9utw90/PG_12_201909212/pgsql_tmp": Not a directory
2022-08-25 00:50:04.629 UTC [34164] LOG:  could not open directory "pg_tblspc/9utw90/PG_12_201909212": Not a directory
2022-08-25 00:50:04.629 UTC [34164] LOG:  could not open directory "pg_tblspc/2r1k5e/PG_12_201909212/pgsql_tmp": Not a directory
2022-08-25 00:50:04.630 UTC [34164] LOG:  could not open directory "pg_tblspc/2r1k5e/PG_12_201909212": Not a directory
2022-08-25 00:50:04.630 UTC [34164] LOG:  could not open directory "pg_tblspc/0diar4/PG_12_201909212/pgsql_tmp": Not a directory
2022-08-25 00:50:04.630 UTC [34164] LOG:  could not open directory "pg_tblspc/0diar4/PG_12_201909212": Not a directory

(this repeats many times only changing the name of the file in pg_tblspace), then:

2022-08-25 00:50:04.632 UTC [34164] LOG:  could not open directory "pg_tblspc/vdmtbt/PG_12_201909212/pgsql_tmp": Not a directory
2022-08-25 00:50:04.632 UTC [34164] LOG:  could not open directory "pg_tblspc/vdmtbt/PG_12_201909212": Not a directory
2022-08-25 00:50:04.650 UTC [34165] LOG:  database system was interrupted while in recovery at 2022-08-24 23:23:07 UTC
2022-08-25 00:50:04.650 UTC [34165] HINT:  This probably means that some data is corrupted and you will have to use the last backup for recovery.
2022-08-25 00:50:07.225 UTC [34165] LOG:  database system was not properly shut down; automatic recovery in progress
2022-08-25 00:50:07.235 UTC [34165] FATAL:  could not open directory "pg_tblspc/9utw90/PG_12_201909212": Not a directory
2022-08-25 00:50:07.237 UTC [34164] LOG:  startup process (PID 34165) exited with exit code 1
2022-08-25 00:50:07.237 UTC [34164] LOG:  aborting startup due to startup process failure
2022-08-25 00:50:07.239 UTC [34164] LOG:  database system is shut down
pg_ctl: could not start server
Examine the log output.

目录中提到的文件pg_tblspc是文件,而不是 Postgres 所期望的目录。老实说,我不知道为什么会发生这种情况,也不知道该如何解决。

编辑:正如评论中所建议的,这是 ls -la 命令的输出:

root@piprod2:/var/lib/postgresql/12/main/pg_tblspc# ls -la 
total 479192
drwx------  2 postgres postgres    4096 Aug 25 13:05 .
drwx------ 19 postgres postgres    4096 Aug 25 12:52 ..
-rwxrwxr-x  1 postgres postgres 4018176 Aug  4 05:57 0diar4
-rwxrwxr-x  1 postgres postgres 1273856 Aug  1 05:02 0ducc7
-rwxrwxr-x  1 postgres postgres       0 Aug 16 09:05 0e7hdr
-rwxrwxr-x  1 postgres postgres 1167360 Aug  7 19:29 0rhy9m
-rwxrwxr-x  1 postgres postgres  385024 Jul 18 18:45 1871ip
-rwxrwxr-x  1 postgres postgres 5648384 Aug 17 05:57 1ata8n
-rwxrwxr-x  1 postgres postgres  937984 Aug 18 19:12 1au1bj
-rwxrwxr-x  1 postgres postgres  503808 Aug  8 05:57 1dnjrw
-rwxrwxr-x  1 postgres postgres 5193728 Aug  7 09:24 1jm5uo
-rwxrwxr-x  1 postgres postgres 5693440 Aug  6 14:35 1oeroe
-rwxrwxr-x  1 postgres postgres 1605632 Aug  8 15:17 1onv4l
-rwxrwxr-x  1 postgres postgres 4976640 Aug 12 07:30 1q3e0k
-rwxrwxr-x  1 postgres postgres  798720 Aug  3 15:28 1z2rle
-rwxrwxr-x  1 postgres postgres 5595136 Aug 19 04:14 2ge92p
-rwxrwxr-x  1 postgres postgres 4091904 Aug  4 17:59 2nsfrv
-rwxrwxr-x  1 postgres postgres  462848 Jul 21 13:28 2o8gkd
-rwxrwxr-x  1 postgres postgres 5107712 Jul 15 19:40 2r1k5e
-rwxrwxr-x  1 postgres postgres  253952 Aug 11 19:30 2x2xup
-rwxrwxr-x  1 postgres postgres 4845568 Aug  9 07:17 35fzzb
-rwxrwxr-x  1 postgres postgres 1466368 Aug  8 02:50 3cck0c
-rwxrwxr-x  1 postgres postgres 3919872 Jul 31 23:31 3dyld3
-rwxrwxr-x  1 postgres postgres  233472 Aug 17 12:05 3fmdws
-rwxrwxr-x  1 postgres postgres  552960 Jul 30 10:15 3moffs
-rwxrwxr-x  1 postgres postgres 5128192 Aug 11 04:15 46ovj2
-rwxrwxr-x  1 postgres postgres 4849664 Aug  6 15:27 4ulprr
-rwxrwxr-x  1 postgres postgres  335872 Jul  8 02:13 4z2vt8
-rwxrwxr-x  1 postgres postgres 3477504 Aug  1 20:51 524tcn
-rwxrwxr-x  1 postgres postgres 1695744 Jul 31 02:10 55qwcx
-rwxrwxr-x  1 postgres postgres  438272 Aug  2 21:34 58xaws
-rwxrwxr-x  1 postgres postgres 3457024 Aug 10 16:20 5a7al4
-rwxrwxr-x  1 postgres postgres 3862528 Aug  8 09:38 5rqdvo
-rwxrwxr-x  1 postgres postgres 4001792 Aug 18 06:17 5sx1zt
-rwxrwxr-x  1 postgres postgres 2269184 Aug  5 08:05 61o00d
-rwxrwxr-x  1 postgres postgres 4288512 Aug 13 02:33 6kidl3
-rwxrwxr-x  1 postgres postgres 5451776 Aug  4 22:48 6qeqkl
-rwxrwxr-x  1 postgres postgres 1708032 Aug  1 01:33 6tqxla
-rwxrwxr-x  1 postgres postgres 3612672 Aug 18 09:23 7bw7me
-rwxrwxr-x  1 postgres postgres  634880 Aug 18 19:35 7fer9p
-rwxrwxr-x  1 postgres postgres 3932160 Aug 10 02:21 7g3v25
-rwxrwxr-x  1 postgres postgres 2895872 Aug  7 23:31 7jwrug
-rwxrwxr-x  1 postgres postgres 3923968 Aug  4 11:30 7ookjl
-rwxrwxr-x  1 postgres postgres 2174976 Aug  4 02:40 8117zg
-rwxrwxr-x  1 postgres postgres 2895872 Aug  8 11:26 8hurij
-rwxrwxr-x  1 postgres postgres 2277376 Aug 17 06:50 8kb23i
-rwxrwxr-x  1 postgres postgres 4595712 Aug 14 03:17 906u7q
-rwxrwxr-x  1 postgres postgres 5419008 Aug 14 14:18 9939r2
-rwxrwxr-x  1 postgres postgres 3190784 Aug  6 15:11 9c9pom
-rwxrwxr-x  1 postgres postgres 2084864 Jul 30 22:00 9rsc65
-rwxrwxr-x  1 postgres postgres 3522560 Aug  2 12:55 9utw90
-rwxrwxr-x  1 postgres postgres 1134592 Aug  1 05:07 afrzmu
-rwxrwxr-x  1 postgres postgres 5730304 Aug  1 04:38 ake4cz
-rwxrwxr-x  1 postgres postgres 1552384 Jul 31 18:52 au9158
-rwxrwxr-x  1 postgres postgres 1921024 Aug  9 12:59 aucnts
-rwxrwxr-x  1 postgres postgres 4505600 Aug  4 04:57 az6mvg
-rwxrwxr-x  1 postgres postgres 1728512 Jul 27 01:13 b4rwj5
-rwxrwxr-x  1 postgres postgres 2842624 Aug  9 19:24 b5x61f
-rwxrwxr-x  1 postgres postgres  364544 Jul 23 23:44 b7v5vq
-rwxrwxr-x  1 postgres postgres 4554752 Jul 30 07:59 b8xazx
-rwxrwxr-x  1 postgres postgres 4386816 Aug  5 11:50 baquiy
-rwxrwxr-x  1 postgres postgres 1368064 Aug  3 02:48 bk75hg
-rwxrwxr-x  1 postgres postgres  847872 Jul 31 21:21 cllsco
-rwxrwxr-x  1 postgres postgres 3883008 Aug 16 05:03 dziej0
-rwxrwxr-x  1 postgres postgres 1204224 Aug 10 20:07 ejmbep
-rwxrwxr-x  1 postgres postgres 3993600 Aug  2 12:00 enwzyf
-rwxrwxr-x  1 postgres postgres       0 Aug 12 17:55 f2sbls
-rwxrwxr-x  1 postgres postgres 3518464 Aug  5 09:45 f63wbk
-rwxrwxr-x  1 postgres postgres 5623808 Aug  3 17:28 f80oyv
-rwxrwxr-x  1 postgres postgres 1298432 Aug 13 22:41 f8bjh5
-rwxrwxr-x  1 postgres postgres 2269184 Jul 17 11:28 f90usz
-rwxrwxr-x  1 postgres postgres 1069056 Aug 16 04:49 fetj2x
-rwxrwxr-x  1 postgres postgres 3137536 Aug  3 11:51 fl2pcb
-rwxrwxr-x  1 postgres postgres 5550080 Aug 13 06:16 fuvorm
-rwxrwxr-x  1 postgres postgres  761856 Aug 16 22:20 fznuyb
-rwxrwxr-x  1 postgres postgres 4198400 Aug 13 03:24 g29f35
-rwxrwxr-x  1 postgres postgres 5509120 Jul 27 14:37 g4vdbu
-rwxrwxr-x  1 postgres postgres  897024 Aug  8 06:33 gclrxl
-rwxrwxr-x  1 postgres postgres 1957888 Jul  5 10:52 gdgh8f
-rwxrwxr-x  1 postgres postgres 3665920 Aug  6 07:44 gnwd7z
-rwxrwxr-x  1 postgres postgres 5713920 Jul 31 07:31 h0256h
-rwxrwxr-x  1 postgres postgres 2076672 Aug  2 14:10 h2xy9t
-rwxrwxr-x  1 postgres postgres  536576 Aug  6 08:57 hcvsq1
-rwxrwxr-x  1 postgres postgres 3129344 Jul 30 20:07 hk7sv5
-rwxrwxr-x  1 postgres postgres 1785856 Jul 30 23:14 hmv7ca
-rwxrwxr-x  1 postgres postgres 3133440 Aug 18 21:40 hrt1yd
-rwxrwxr-x  1 postgres postgres 2289664 Aug  8 14:20 i3ah5f
-rwxrwxr-x  1 postgres postgres 3772416 Jul 27 03:35 i6p4fx
-rwxrwxr-x  1 postgres postgres 1024000 Jul 28 15:28 i7ruyy
-rwxrwxr-x  1 postgres postgres 4186112 Aug 12 17:23 ihm5al
-rwxrwxr-x  1 postgres postgres 2355200 Aug 14 23:03 ko3jd4
-rwxrwxr-x  1 postgres postgres 2441216 Aug  5 18:53 kr1qgn
-rwxrwxr-x  1 postgres postgres 4820992 Aug  3 11:25 kylx64
-rwxrwxr-x  1 postgres postgres 2789376 Aug  1 05:00 l92hlb
-rwxrwxr-x  1 postgres postgres 1339392 Aug 14 06:16 lhvk99
-rwxrwxr-x  1 postgres postgres 4382720 Aug 13 22:03 liry5d
-rwxrwxr-x  1 postgres postgres  348160 Jul 27 15:19 llnuof
-rwxrwxr-x  1 postgres postgres 1269760 Aug  7 09:57 lugh96
-rwxrwxr-x  1 postgres postgres 3608576 Aug  6 16:58 m6si40
-rwxrwxr-x  1 postgres postgres 3739648 Aug  7 22:22 m6uscq
-rwxrwxr-x  1 postgres postgres 2027520 Jul 31 12:41 m8fhgq
-rwxrwxr-x  1 postgres postgres 4669440 Aug 18 03:22 mj9hn7
-rwxrwxr-x  1 postgres postgres 2785280 Aug 10 11:35 n164bh
-rwxrwxr-x  1 postgres postgres  483328 Aug 17 11:01 n27g0g
-rwxrwxr-x  1 postgres postgres 5267456 Aug 10 00:12 ntpsfq
-rwxrwxr-x  1 postgres postgres 4411392 Aug 16 02:31 nv2gal
-rwxrwxr-x  1 postgres postgres 2805760 Aug  5 05:39 o2qeyb
-rwxrwxr-x  1 postgres postgres 5201920 Jul 28 13:15 o36yer
-rwxrwxr-x  1 postgres postgres 2662400 Jul 23 01:54 oaj27w
-rwxrwxr-x  1 postgres postgres 4345856 Aug  6 06:36 ohzeep
-rwxrwxr-x  1 postgres postgres 3039232 Jul 15 22:31 oid1ug
-rwxrwxr-x  1 postgres postgres 5705728 Jul 31 23:38 op6jrb
-rwxrwxr-x  1 postgres postgres 4669440 Aug 18 10:31 oqh0ns
-rwxrwxr-x  1 postgres postgres 2244608 Jul 29 23:12 p0r4db
-rwxrwxr-x  1 postgres postgres 5505024 Jul 13 19:20 pg5v7y
-rwxrwxr-x  1 postgres postgres 1187840 Jul 22 11:46 pow0m3
-rwxrwxr-x  1 postgres postgres 3485696 Jul 19 12:12 q61j9f
-rwxrwxr-x  1 postgres postgres 2994176 Aug 18 23:09 q8drbm
-rwxrwxr-x  1 postgres postgres 2846720 Aug 16 04:52 qijaez
-rwxrwxr-x  1 postgres postgres 2555904 Aug  2 17:54 ql8h20
-rwxrwxr-x  1 postgres postgres  229376 Aug  3 16:09 qq438k
-rwxrwxr-x  1 postgres postgres 4374528 Aug 16 03:46 ri1moh
-rwxrwxr-x  1 postgres postgres 1208320 Aug 10 21:46 ri7kwd
-rwxrwxr-x  1 postgres postgres 1671168 Aug 13 03:20 rprlyh
-rwxrwxr-x  1 postgres postgres 2740224 Jul 21 13:22 rrigy1
-rwxrwxr-x  1 postgres postgres 2928640 Aug 13 10:06 rsiqwd
-rwxrwxr-x  1 postgres postgres 4517888 Aug 15 10:47 rvvbt5
-rwxrwxr-x  1 postgres postgres 3043328 Aug  8 01:27 snak0w
-rwxrwxr-x  1 postgres postgres 1380352 Jul 27 05:26 t3vprk
-rwxrwxr-x  1 postgres postgres 5001216 Jul 30 15:03 t9qgu5
-rwxrwxr-x  1 postgres postgres  167936 Jul 22 11:50 tpmy34
-rwxrwxr-x  1 postgres postgres 4968448 Aug  4 02:39 tr54uf
-rwxrwxr-x  1 postgres postgres 2404352 Jul 10 18:43 u3turb
-rwxrwxr-x  1 postgres postgres  270336 Jul 30 19:06 u744id
-rwxrwxr-x  1 postgres postgres 4788224 Aug  9 22:26 u866ms
-rwxrwxr-x  1 postgres postgres 3100672 Aug  3 08:01 ubwlni
-rwxrwxr-x  1 postgres postgres 5672960 Jul 30 09:20 uebfm0
-rwxrwxr-x  1 postgres postgres 2502656 Jul 26 11:52 ugj4u7
-rwxrwxr-x  1 postgres postgres  262144 Jul 27 10:58 uobz25
-rwxrwxr-x  1 postgres postgres 1138688 Aug  8 03:13 urbcvq
-rwxrwxr-x  1 postgres postgres 5402624 Aug  1 07:03 uvyc01
-rwxrwxr-x  1 postgres postgres 3379200 Jul 24 22:02 v62hwd
-rwxrwxr-x  1 postgres postgres 1773568 Jul 30 17:28 va02le
-rwxrwxr-x  1 postgres postgres 3248128 Aug 15 02:30 vcdump
-rwxrwxr-x  1 postgres postgres 3440640 Aug  3 08:05 vdmtbt
-rwxrwxr-x  1 postgres postgres 1622016 Aug 18 19:47 ve15n1
-rwxrwxr-x  1 postgres postgres 3784704 Aug  5 07:37 ve832g
-rwxrwxr-x  1 postgres postgres 1294336 Aug 11 05:28 vgzf36
-rwxrwxr-x  1 postgres postgres  851968 Jul 23 04:16 viw6qe
-rwxrwxr-x  1 postgres postgres  946176 Aug  9 05:30 w0byer
-rwxrwxr-x  1 postgres postgres  233472 Aug 13 23:09 w9j2o8
-rwxrwxr-x  1 postgres postgres 2469888 Aug  6 09:25 wejngt
-rwxrwxr-x  1 postgres postgres 5255168 Jul 26 21:27 wh7jom
-rwxrwxr-x  1 postgres postgres 1585152 Jul 25 22:28 wl8uyw
-rwxrwxr-x  1 postgres postgres 4177920 Jul 31 00:57 wlm9e8
-rwxrwxr-x  1 postgres postgres 4718592 Aug  5 04:24 wo979o
-rwxrwxr-x  1 postgres postgres 4694016 Aug 18 23:26 wua277
-rwxrwxr-x  1 postgres postgres 5781824 Aug  1 02:30 xayuy0
-rwxrwxr-x  1 postgres postgres 3379200 Jul  7 15:09 xgag4f
-rwxrwxr-x  1 postgres postgres 2383872 Aug  3 12:13 xq8l6m
-rwxrwxr-x  1 postgres postgres 5701632 Aug  7 06:46 xr5j1x
-rwxrwxr-x  1 postgres postgres 5443584 Aug 15 12:06 xuttiu
-rwxrwxr-x  1 postgres postgres 5537792 Aug 18 23:39 xzudeh
-rwxrwxr-x  1 postgres postgres  151552 Aug 13 16:44 y6d7m1
-rwxrwxr-x  1 postgres postgres 4161536 Aug 16 09:10 ytbwys
-rwxrwxr-x  1 postgres postgres 1929216 Aug 19 04:24 yyu9qw
-rwxrwxr-x  1 postgres postgres 4661248 Jul 31 13:36 z0qt82
-rwxrwxr-x  1 postgres postgres 1413120 Aug 11 15:36 ziwphs
-rwxrwxr-x  1 postgres postgres 4911104 Aug  5 02:52 zkixlp

那么,现在是备份时间了,对吗?嗯,不是。

然后我想,哎呀,是时候恢复一些备份了。这是在 Azure VM 中运行的,具有每日映像备份(尚未启用数据库备份),我有 30 天的映像要恢复,但无论我选择并恢复哪一个,问题都会再次出现。即使我使用该图像启动一个全新的虚拟机,但使用 15 天前的旧数据,当系统正常运行时,它会出现同样的错误。

因此,如果您能提供任何帮助,我们将不胜感激。谢谢。

答案1

好吧,我通过一些蛮力解决了这个问题,即pg_tblspc在备份文件夹后删除文件夹的内容。理由是,在默认表空间中它应该是空的,而且我不能把它弄得更乱。Postgres 启动了,数据似乎没问题。

感谢@NikitaKipriyanov 在评论中提供的帮助。

相关内容