pg_query 5.0.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (898) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +27 -0
  3. data/README.md +1 -1
  4. data/Rakefile +3 -4
  5. data/ext/pg_query/extconf.rb +14 -4
  6. data/ext/pg_query/include/pg_query.h +4 -3
  7. data/ext/pg_query/include/pg_query_enum_defs.c +424 -154
  8. data/ext/pg_query/include/pg_query_fingerprint_conds.c +68 -4
  9. data/ext/pg_query/include/pg_query_fingerprint_defs.c +2901 -1794
  10. data/ext/pg_query/include/pg_query_outfuncs_conds.c +51 -3
  11. data/ext/pg_query/include/pg_query_outfuncs_defs.c +211 -24
  12. data/ext/pg_query/include/pg_query_readfuncs_conds.c +17 -1
  13. data/ext/pg_query/include/pg_query_readfuncs_defs.c +272 -53
  14. data/ext/pg_query/include/postgres/access/amapi.h +299 -0
  15. data/ext/pg_query/include/postgres/access/attmap.h +54 -0
  16. data/ext/pg_query/include/postgres/access/attnum.h +64 -0
  17. data/ext/pg_query/include/postgres/access/brin_internal.h +116 -0
  18. data/ext/pg_query/include/postgres/access/brin_tuple.h +112 -0
  19. data/ext/pg_query/include/postgres/access/clog.h +62 -0
  20. data/ext/pg_query/include/postgres/access/commit_ts.h +73 -0
  21. data/ext/pg_query/include/postgres/access/detoast.h +82 -0
  22. data/ext/pg_query/include/postgres/access/genam.h +237 -0
  23. data/ext/pg_query/include/postgres/access/gin.h +91 -0
  24. data/ext/pg_query/include/postgres/access/htup.h +89 -0
  25. data/ext/pg_query/include/postgres/access/htup_details.h +811 -0
  26. data/ext/pg_query/include/postgres/access/itup.h +170 -0
  27. data/ext/pg_query/include/postgres/access/parallel.h +81 -0
  28. data/ext/pg_query/include/postgres/access/printtup.h +35 -0
  29. data/ext/pg_query/include/postgres/access/relation.h +28 -0
  30. data/ext/pg_query/include/postgres/access/relscan.h +191 -0
  31. data/ext/pg_query/include/postgres/access/rmgrlist.h +49 -0
  32. data/ext/pg_query/include/postgres/access/sdir.h +67 -0
  33. data/ext/pg_query/include/postgres/access/skey.h +151 -0
  34. data/ext/pg_query/include/postgres/access/slru.h +221 -0
  35. data/ext/pg_query/include/postgres/access/stratnum.h +85 -0
  36. data/ext/pg_query/include/postgres/access/sysattr.h +29 -0
  37. data/ext/pg_query/include/postgres/access/table.h +28 -0
  38. data/ext/pg_query/include/postgres/access/tableam.h +2109 -0
  39. data/ext/pg_query/include/postgres/access/tidstore.h +50 -0
  40. data/ext/pg_query/include/postgres/access/toast_compression.h +73 -0
  41. data/ext/pg_query/include/postgres/access/transam.h +375 -0
  42. data/ext/pg_query/include/postgres/access/tsmapi.h +82 -0
  43. data/ext/pg_query/include/postgres/access/tupconvert.h +54 -0
  44. data/ext/pg_query/include/postgres/access/tupdesc.h +154 -0
  45. data/ext/pg_query/include/postgres/access/tupmacs.h +207 -0
  46. data/ext/pg_query/include/postgres/access/twophase.h +65 -0
  47. data/ext/pg_query/include/postgres/access/xact.h +530 -0
  48. data/ext/pg_query/include/postgres/access/xlog.h +310 -0
  49. data/ext/pg_query/include/postgres/access/xlog_internal.h +405 -0
  50. data/ext/pg_query/include/postgres/access/xlogbackup.h +43 -0
  51. data/ext/pg_query/include/postgres/access/xlogdefs.h +82 -0
  52. data/ext/pg_query/include/postgres/access/xlogprefetcher.h +55 -0
  53. data/ext/pg_query/include/postgres/access/xlogreader.h +444 -0
  54. data/ext/pg_query/include/postgres/access/xlogrecord.h +248 -0
  55. data/ext/pg_query/include/postgres/access/xlogrecovery.h +158 -0
  56. data/ext/pg_query/include/postgres/archive/archive_module.h +67 -0
  57. data/ext/pg_query/include/postgres/c.h +1374 -0
  58. data/ext/pg_query/include/postgres/catalog/catalog.h +47 -0
  59. data/ext/pg_query/include/postgres/catalog/catversion.h +62 -0
  60. data/ext/pg_query/include/postgres/catalog/dependency.h +228 -0
  61. data/ext/pg_query/include/postgres/catalog/genbki.h +149 -0
  62. data/ext/pg_query/include/postgres/catalog/index.h +218 -0
  63. data/ext/pg_query/include/postgres/catalog/indexing.h +54 -0
  64. data/ext/pg_query/include/postgres/catalog/namespace.h +189 -0
  65. data/ext/pg_query/include/postgres/catalog/objectaccess.h +267 -0
  66. data/ext/pg_query/include/postgres/catalog/objectaddress.h +89 -0
  67. data/ext/pg_query/include/postgres/catalog/pg_aggregate.h +182 -0
  68. data/ext/pg_query/include/postgres/catalog/pg_aggregate_d.h +78 -0
  69. data/ext/pg_query/include/postgres/catalog/pg_am.h +66 -0
  70. data/ext/pg_query/include/postgres/catalog/pg_am_d.h +47 -0
  71. data/ext/pg_query/include/postgres/catalog/pg_attribute.h +240 -0
  72. data/ext/pg_query/include/postgres/catalog/pg_attribute_d.h +62 -0
  73. data/ext/pg_query/include/postgres/catalog/pg_authid.h +66 -0
  74. data/ext/pg_query/include/postgres/catalog/pg_authid_d.h +60 -0
  75. data/ext/pg_query/include/postgres/catalog/pg_class.h +235 -0
  76. data/ext/pg_query/include/postgres/catalog/pg_class_d.h +134 -0
  77. data/ext/pg_query/include/postgres/catalog/pg_collation.h +106 -0
  78. data/ext/pg_query/include/postgres/catalog/pg_collation_d.h +66 -0
  79. data/ext/pg_query/include/postgres/catalog/pg_constraint.h +278 -0
  80. data/ext/pg_query/include/postgres/catalog/pg_constraint_d.h +74 -0
  81. data/ext/pg_query/include/postgres/catalog/pg_control.h +260 -0
  82. data/ext/pg_query/include/postgres/catalog/pg_conversion.h +79 -0
  83. data/ext/pg_query/include/postgres/catalog/pg_conversion_d.h +38 -0
  84. data/ext/pg_query/include/postgres/catalog/pg_database.h +129 -0
  85. data/ext/pg_query/include/postgres/catalog/pg_database_d.h +53 -0
  86. data/ext/pg_query/include/postgres/catalog/pg_depend.h +77 -0
  87. data/ext/pg_query/include/postgres/catalog/pg_depend_d.h +36 -0
  88. data/ext/pg_query/include/postgres/catalog/pg_event_trigger.h +60 -0
  89. data/ext/pg_query/include/postgres/catalog/pg_event_trigger_d.h +36 -0
  90. data/ext/pg_query/include/postgres/catalog/pg_index.h +92 -0
  91. data/ext/pg_query/include/postgres/catalog/pg_index_d.h +59 -0
  92. data/ext/pg_query/include/postgres/catalog/pg_language.h +75 -0
  93. data/ext/pg_query/include/postgres/catalog/pg_language_d.h +41 -0
  94. data/ext/pg_query/include/postgres/catalog/pg_namespace.h +67 -0
  95. data/ext/pg_query/include/postgres/catalog/pg_namespace_d.h +36 -0
  96. data/ext/pg_query/include/postgres/catalog/pg_opclass.h +91 -0
  97. data/ext/pg_query/include/postgres/catalog/pg_opclass_d.h +51 -0
  98. data/ext/pg_query/include/postgres/catalog/pg_operator.h +124 -0
  99. data/ext/pg_query/include/postgres/catalog/pg_operator_d.h +142 -0
  100. data/ext/pg_query/include/postgres/catalog/pg_opfamily.h +67 -0
  101. data/ext/pg_query/include/postgres/catalog/pg_opfamily_d.h +51 -0
  102. data/ext/pg_query/include/postgres/catalog/pg_partitioned_table.h +76 -0
  103. data/ext/pg_query/include/postgres/catalog/pg_partitioned_table_d.h +36 -0
  104. data/ext/pg_query/include/postgres/catalog/pg_proc.h +223 -0
  105. data/ext/pg_query/include/postgres/catalog/pg_proc_d.h +101 -0
  106. data/ext/pg_query/include/postgres/catalog/pg_publication.h +161 -0
  107. data/ext/pg_query/include/postgres/catalog/pg_publication_d.h +38 -0
  108. data/ext/pg_query/include/postgres/catalog/pg_replication_origin.h +65 -0
  109. data/ext/pg_query/include/postgres/catalog/pg_replication_origin_d.h +33 -0
  110. data/ext/pg_query/include/postgres/catalog/pg_statistic.h +288 -0
  111. data/ext/pg_query/include/postgres/catalog/pg_statistic_d.h +199 -0
  112. data/ext/pg_query/include/postgres/catalog/pg_statistic_ext.h +91 -0
  113. data/ext/pg_query/include/postgres/catalog/pg_statistic_ext_d.h +45 -0
  114. data/ext/pg_query/include/postgres/catalog/pg_transform.h +51 -0
  115. data/ext/pg_query/include/postgres/catalog/pg_transform_d.h +34 -0
  116. data/ext/pg_query/include/postgres/catalog/pg_trigger.h +153 -0
  117. data/ext/pg_query/include/postgres/catalog/pg_trigger_d.h +109 -0
  118. data/ext/pg_query/include/postgres/catalog/pg_ts_config.h +56 -0
  119. data/ext/pg_query/include/postgres/catalog/pg_ts_config_d.h +34 -0
  120. data/ext/pg_query/include/postgres/catalog/pg_ts_dict.h +62 -0
  121. data/ext/pg_query/include/postgres/catalog/pg_ts_dict_d.h +35 -0
  122. data/ext/pg_query/include/postgres/catalog/pg_ts_parser.h +63 -0
  123. data/ext/pg_query/include/postgres/catalog/pg_ts_parser_d.h +37 -0
  124. data/ext/pg_query/include/postgres/catalog/pg_ts_template.h +54 -0
  125. data/ext/pg_query/include/postgres/catalog/pg_ts_template_d.h +34 -0
  126. data/ext/pg_query/include/postgres/catalog/pg_type.h +407 -0
  127. data/ext/pg_query/include/postgres/catalog/pg_type_d.h +324 -0
  128. data/ext/pg_query/include/postgres/catalog/storage.h +50 -0
  129. data/ext/pg_query/include/postgres/catalog/syscache_ids.h +104 -0
  130. data/ext/pg_query/include/postgres/commands/async.h +49 -0
  131. data/ext/pg_query/include/postgres/commands/dbcommands.h +37 -0
  132. data/ext/pg_query/include/postgres/commands/defrem.h +161 -0
  133. data/ext/pg_query/include/postgres/commands/event_trigger.h +91 -0
  134. data/ext/pg_query/include/postgres/commands/explain.h +145 -0
  135. data/ext/pg_query/include/postgres/commands/prepare.h +61 -0
  136. data/ext/pg_query/include/postgres/commands/tablespace.h +69 -0
  137. data/ext/pg_query/include/postgres/commands/trigger.h +288 -0
  138. data/ext/pg_query/include/postgres/commands/vacuum.h +388 -0
  139. data/ext/pg_query/include/postgres/common/cryptohash.h +39 -0
  140. data/ext/pg_query/include/postgres/common/file_perm.h +56 -0
  141. data/ext/pg_query/include/postgres/common/file_utils.h +65 -0
  142. data/ext/pg_query/include/postgres/common/hashfn.h +119 -0
  143. data/ext/pg_query/include/postgres/common/hashfn_unstable.h +453 -0
  144. data/ext/pg_query/include/postgres/common/int.h +512 -0
  145. data/ext/pg_query/include/postgres/common/keywords.h +29 -0
  146. data/ext/pg_query/include/postgres/common/kwlookup.h +44 -0
  147. data/ext/pg_query/include/postgres/common/pg_prng.h +62 -0
  148. data/ext/pg_query/include/postgres/common/relpath.h +97 -0
  149. data/ext/pg_query/include/postgres/common/scram-common.h +70 -0
  150. data/ext/pg_query/include/postgres/common/sha2.h +32 -0
  151. data/ext/pg_query/include/postgres/common/string.h +44 -0
  152. data/ext/pg_query/include/postgres/common/unicode_east_asian_fw_table.h +124 -0
  153. data/ext/pg_query/include/postgres/copyfuncs.funcs.c +5261 -0
  154. data/ext/pg_query/include/postgres/copyfuncs.switch.c +989 -0
  155. data/ext/pg_query/include/postgres/datatype/timestamp.h +269 -0
  156. data/ext/pg_query/include/postgres/equalfuncs.funcs.c +3310 -0
  157. data/ext/pg_query/include/postgres/equalfuncs.switch.c +836 -0
  158. data/ext/pg_query/include/postgres/executor/execdesc.h +70 -0
  159. data/ext/pg_query/include/postgres/executor/executor.h +681 -0
  160. data/ext/pg_query/include/postgres/executor/functions.h +56 -0
  161. data/ext/pg_query/include/postgres/executor/instrument.h +120 -0
  162. data/ext/pg_query/include/postgres/executor/spi.h +207 -0
  163. data/ext/pg_query/include/postgres/executor/tablefunc.h +67 -0
  164. data/ext/pg_query/include/postgres/executor/tuptable.h +523 -0
  165. data/ext/pg_query/include/postgres/fmgr.h +800 -0
  166. data/ext/pg_query/include/postgres/foreign/fdwapi.h +294 -0
  167. data/ext/pg_query/include/postgres/funcapi.h +360 -0
  168. data/ext/pg_query/include/postgres/gram.h +1168 -0
  169. data/ext/pg_query/include/postgres/gramparse.h +75 -0
  170. data/ext/pg_query/include/postgres/jit/jit.h +106 -0
  171. data/ext/pg_query/include/postgres/kwlist_d.h +1164 -0
  172. data/ext/pg_query/include/postgres/lib/dshash.h +130 -0
  173. data/ext/pg_query/include/postgres/lib/ilist.h +1159 -0
  174. data/ext/pg_query/include/postgres/lib/pairingheap.h +102 -0
  175. data/ext/pg_query/include/postgres/lib/simplehash.h +1206 -0
  176. data/ext/pg_query/include/postgres/lib/sort_template.h +445 -0
  177. data/ext/pg_query/include/postgres/lib/stringinfo.h +243 -0
  178. data/ext/pg_query/include/postgres/libpq/auth.h +37 -0
  179. data/ext/pg_query/include/postgres/libpq/crypt.h +47 -0
  180. data/ext/pg_query/include/postgres/libpq/hba.h +186 -0
  181. data/ext/pg_query/include/postgres/libpq/libpq-be.h +358 -0
  182. data/ext/pg_query/include/postgres/libpq/libpq.h +143 -0
  183. data/ext/pg_query/include/postgres/libpq/pqcomm.h +169 -0
  184. data/ext/pg_query/include/postgres/libpq/pqformat.h +209 -0
  185. data/ext/pg_query/include/postgres/libpq/pqsignal.h +54 -0
  186. data/ext/pg_query/include/postgres/libpq/protocol.h +89 -0
  187. data/ext/pg_query/include/postgres/libpq/sasl.h +136 -0
  188. data/ext/pg_query/include/postgres/libpq/scram.h +37 -0
  189. data/ext/pg_query/include/postgres/mb/pg_wchar.h +792 -0
  190. data/ext/pg_query/include/postgres/mb/stringinfo_mb.h +24 -0
  191. data/ext/pg_query/include/postgres/miscadmin.h +519 -0
  192. data/ext/pg_query/include/postgres/nodes/bitmapset.h +140 -0
  193. data/ext/pg_query/include/postgres/nodes/execnodes.h +2852 -0
  194. data/ext/pg_query/include/postgres/nodes/extensible.h +164 -0
  195. data/ext/pg_query/include/postgres/nodes/lockoptions.h +61 -0
  196. data/ext/pg_query/include/postgres/nodes/makefuncs.h +127 -0
  197. data/ext/pg_query/include/postgres/nodes/memnodes.h +152 -0
  198. data/ext/pg_query/include/postgres/nodes/miscnodes.h +56 -0
  199. data/ext/pg_query/include/postgres/nodes/nodeFuncs.h +222 -0
  200. data/ext/pg_query/include/postgres/nodes/nodes.h +435 -0
  201. data/ext/pg_query/include/postgres/nodes/nodetags.h +491 -0
  202. data/ext/pg_query/include/postgres/nodes/params.h +170 -0
  203. data/ext/pg_query/include/postgres/nodes/parsenodes.h +4233 -0
  204. data/ext/pg_query/include/postgres/nodes/pathnodes.h +3435 -0
  205. data/ext/pg_query/include/postgres/nodes/pg_list.h +686 -0
  206. data/ext/pg_query/include/postgres/nodes/plannodes.h +1593 -0
  207. data/ext/pg_query/include/postgres/nodes/primnodes.h +2335 -0
  208. data/ext/pg_query/include/postgres/nodes/print.h +34 -0
  209. data/ext/pg_query/include/postgres/nodes/queryjumble.h +86 -0
  210. data/ext/pg_query/include/postgres/nodes/replnodes.h +132 -0
  211. data/ext/pg_query/include/postgres/nodes/supportnodes.h +346 -0
  212. data/ext/pg_query/include/postgres/nodes/tidbitmap.h +75 -0
  213. data/ext/pg_query/include/postgres/nodes/value.h +90 -0
  214. data/ext/pg_query/include/postgres/optimizer/cost.h +216 -0
  215. data/ext/pg_query/include/postgres/optimizer/geqo.h +90 -0
  216. data/ext/pg_query/include/postgres/optimizer/geqo_gene.h +45 -0
  217. data/ext/pg_query/include/postgres/optimizer/optimizer.h +205 -0
  218. data/ext/pg_query/include/postgres/optimizer/paths.h +271 -0
  219. data/ext/pg_query/include/postgres/optimizer/planmain.h +123 -0
  220. data/ext/pg_query/include/postgres/parser/analyze.h +66 -0
  221. data/ext/pg_query/include/postgres/parser/kwlist.h +518 -0
  222. data/ext/pg_query/include/postgres/parser/parse_agg.h +65 -0
  223. data/ext/pg_query/include/postgres/parser/parse_coerce.h +102 -0
  224. data/ext/pg_query/include/postgres/parser/parse_expr.h +25 -0
  225. data/ext/pg_query/include/postgres/parser/parse_func.h +74 -0
  226. data/ext/pg_query/include/postgres/parser/parse_node.h +358 -0
  227. data/ext/pg_query/include/postgres/parser/parse_oper.h +68 -0
  228. data/ext/pg_query/include/postgres/parser/parse_relation.h +129 -0
  229. data/ext/pg_query/include/postgres/parser/parse_type.h +61 -0
  230. data/ext/pg_query/include/postgres/parser/parser.h +68 -0
  231. data/ext/pg_query/include/postgres/parser/parsetree.h +61 -0
  232. data/ext/pg_query/include/postgres/parser/scanner.h +152 -0
  233. data/ext/pg_query/include/postgres/parser/scansup.h +27 -0
  234. data/ext/pg_query/include/postgres/partitioning/partdefs.h +26 -0
  235. data/ext/pg_query/include/postgres/pg_config.h +977 -0
  236. data/ext/pg_query/include/postgres/pg_config_manual.h +385 -0
  237. data/ext/pg_query/include/postgres/pg_config_os.h +8 -0
  238. data/ext/pg_query/include/postgres/pg_getopt.h +56 -0
  239. data/ext/pg_query/include/postgres/pg_trace.h +17 -0
  240. data/ext/pg_query/include/postgres/pgstat.h +780 -0
  241. data/ext/pg_query/include/postgres/pgtime.h +94 -0
  242. data/ext/pg_query/include/postgres/pl_gram.h +385 -0
  243. data/ext/pg_query/include/postgres/pl_reserved_kwlist.h +52 -0
  244. data/ext/pg_query/include/postgres/pl_reserved_kwlist_d.h +114 -0
  245. data/ext/pg_query/include/postgres/pl_unreserved_kwlist.h +112 -0
  246. data/ext/pg_query/include/postgres/pl_unreserved_kwlist_d.h +246 -0
  247. data/ext/pg_query/include/postgres/plerrcodes.h +998 -0
  248. data/ext/pg_query/include/postgres/plpgsql.h +1342 -0
  249. data/ext/pg_query/include/postgres/port/atomics/arch-arm.h +32 -0
  250. data/ext/pg_query/include/postgres/port/atomics/arch-hppa.h +17 -0
  251. data/ext/pg_query/include/postgres/port/atomics/arch-ppc.h +256 -0
  252. data/ext/pg_query/include/postgres/port/atomics/arch-x86.h +254 -0
  253. data/ext/pg_query/include/postgres/port/atomics/fallback.h +170 -0
  254. data/ext/pg_query/include/postgres/port/atomics/generic-gcc.h +323 -0
  255. data/ext/pg_query/include/postgres/port/atomics/generic-msvc.h +119 -0
  256. data/ext/pg_query/include/postgres/port/atomics/generic-sunpro.h +121 -0
  257. data/ext/pg_query/include/postgres/port/atomics/generic.h +437 -0
  258. data/ext/pg_query/include/postgres/port/atomics.h +606 -0
  259. data/ext/pg_query/include/postgres/port/pg_bitutils.h +421 -0
  260. data/ext/pg_query/include/postgres/port/pg_bswap.h +161 -0
  261. data/ext/pg_query/include/postgres/port/pg_crc32c.h +110 -0
  262. data/ext/pg_query/include/postgres/port/pg_iovec.h +117 -0
  263. data/ext/pg_query/include/postgres/port/simd.h +422 -0
  264. data/ext/pg_query/include/postgres/port/win32/arpa/inet.h +3 -0
  265. data/ext/pg_query/include/postgres/port/win32/dlfcn.h +1 -0
  266. data/ext/pg_query/include/postgres/port/win32/grp.h +1 -0
  267. data/ext/pg_query/include/postgres/port/win32/netdb.h +7 -0
  268. data/ext/pg_query/include/postgres/port/win32/netinet/in.h +3 -0
  269. data/ext/pg_query/include/postgres/port/win32/netinet/tcp.h +7 -0
  270. data/ext/pg_query/include/postgres/port/win32/pwd.h +3 -0
  271. data/ext/pg_query/include/postgres/port/win32/sys/resource.h +20 -0
  272. data/ext/pg_query/include/postgres/port/win32/sys/select.h +3 -0
  273. data/ext/pg_query/include/postgres/port/win32/sys/socket.h +34 -0
  274. data/ext/pg_query/include/postgres/port/win32/sys/un.h +17 -0
  275. data/ext/pg_query/include/postgres/port/win32/sys/wait.h +3 -0
  276. data/ext/pg_query/include/postgres/port/win32.h +59 -0
  277. data/ext/pg_query/include/postgres/port/win32_msvc/dirent.h +34 -0
  278. data/ext/pg_query/include/postgres/port/win32_msvc/sys/file.h +1 -0
  279. data/ext/pg_query/include/postgres/port/win32_msvc/sys/param.h +1 -0
  280. data/ext/pg_query/include/postgres/port/win32_msvc/sys/time.h +1 -0
  281. data/ext/pg_query/include/postgres/port/win32_msvc/unistd.h +9 -0
  282. data/ext/pg_query/include/postgres/port/win32_msvc/utime.h +3 -0
  283. data/ext/pg_query/include/postgres/port/win32_port.h +584 -0
  284. data/ext/pg_query/include/postgres/port.h +524 -0
  285. data/ext/pg_query/include/postgres/portability/instr_time.h +197 -0
  286. data/ext/pg_query/include/postgres/postgres.h +579 -0
  287. data/ext/pg_query/include/postgres/postmaster/autovacuum.h +69 -0
  288. data/ext/pg_query/include/postgres/postmaster/bgworker.h +164 -0
  289. data/ext/pg_query/include/postgres/postmaster/bgworker_internals.h +60 -0
  290. data/ext/pg_query/include/postgres/postmaster/bgwriter.h +45 -0
  291. data/ext/pg_query/include/postgres/postmaster/interrupt.h +32 -0
  292. data/ext/pg_query/include/postgres/postmaster/pgarch.h +36 -0
  293. data/ext/pg_query/include/postgres/postmaster/postmaster.h +101 -0
  294. data/ext/pg_query/include/postgres/postmaster/startup.h +41 -0
  295. data/ext/pg_query/include/postgres/postmaster/syslogger.h +101 -0
  296. data/ext/pg_query/include/postgres/postmaster/walsummarizer.h +35 -0
  297. data/ext/pg_query/include/postgres/postmaster/walwriter.h +23 -0
  298. data/ext/pg_query/include/postgres/regex/regex.h +272 -0
  299. data/ext/pg_query/include/postgres/replication/logicallauncher.h +34 -0
  300. data/ext/pg_query/include/postgres/replication/logicalproto.h +274 -0
  301. data/ext/pg_query/include/postgres/replication/logicalworker.h +33 -0
  302. data/ext/pg_query/include/postgres/replication/origin.h +73 -0
  303. data/ext/pg_query/include/postgres/replication/reorderbuffer.h +743 -0
  304. data/ext/pg_query/include/postgres/replication/slot.h +285 -0
  305. data/ext/pg_query/include/postgres/replication/slotsync.h +38 -0
  306. data/ext/pg_query/include/postgres/replication/syncrep.h +109 -0
  307. data/ext/pg_query/include/postgres/replication/walreceiver.h +504 -0
  308. data/ext/pg_query/include/postgres/replication/walsender.h +76 -0
  309. data/ext/pg_query/include/postgres/rewrite/prs2lock.h +46 -0
  310. data/ext/pg_query/include/postgres/rewrite/rewriteHandler.h +41 -0
  311. data/ext/pg_query/include/postgres/rewrite/rewriteManip.h +96 -0
  312. data/ext/pg_query/include/postgres/rewrite/rewriteSupport.h +26 -0
  313. data/ext/pg_query/include/postgres/storage/block.h +108 -0
  314. data/ext/pg_query/include/postgres/storage/buf.h +46 -0
  315. data/ext/pg_query/include/postgres/storage/bufmgr.h +411 -0
  316. data/ext/pg_query/include/postgres/storage/bufpage.h +510 -0
  317. data/ext/pg_query/include/postgres/storage/condition_variable.h +73 -0
  318. data/ext/pg_query/include/postgres/storage/dsm.h +61 -0
  319. data/ext/pg_query/include/postgres/storage/dsm_impl.h +79 -0
  320. data/ext/pg_query/include/postgres/storage/fd.h +219 -0
  321. data/ext/pg_query/include/postgres/storage/fileset.h +40 -0
  322. data/ext/pg_query/include/postgres/storage/ipc.h +87 -0
  323. data/ext/pg_query/include/postgres/storage/item.h +19 -0
  324. data/ext/pg_query/include/postgres/storage/itemid.h +184 -0
  325. data/ext/pg_query/include/postgres/storage/itemptr.h +245 -0
  326. data/ext/pg_query/include/postgres/storage/large_object.h +100 -0
  327. data/ext/pg_query/include/postgres/storage/latch.h +196 -0
  328. data/ext/pg_query/include/postgres/storage/lmgr.h +126 -0
  329. data/ext/pg_query/include/postgres/storage/lock.h +624 -0
  330. data/ext/pg_query/include/postgres/storage/lockdefs.h +59 -0
  331. data/ext/pg_query/include/postgres/storage/lwlock.h +228 -0
  332. data/ext/pg_query/include/postgres/storage/lwlocknames.h +47 -0
  333. data/ext/pg_query/include/postgres/storage/off.h +57 -0
  334. data/ext/pg_query/include/postgres/storage/pg_sema.h +61 -0
  335. data/ext/pg_query/include/postgres/storage/pg_shmem.h +93 -0
  336. data/ext/pg_query/include/postgres/storage/pmsignal.h +105 -0
  337. data/ext/pg_query/include/postgres/storage/predicate.h +83 -0
  338. data/ext/pg_query/include/postgres/storage/proc.h +491 -0
  339. data/ext/pg_query/include/postgres/storage/procarray.h +103 -0
  340. data/ext/pg_query/include/postgres/storage/proclist_types.h +53 -0
  341. data/ext/pg_query/include/postgres/storage/procnumber.h +43 -0
  342. data/ext/pg_query/include/postgres/storage/procsignal.h +75 -0
  343. data/ext/pg_query/include/postgres/storage/read_stream.h +65 -0
  344. data/ext/pg_query/include/postgres/storage/relfilelocator.h +100 -0
  345. data/ext/pg_query/include/postgres/storage/s_lock.h +847 -0
  346. data/ext/pg_query/include/postgres/storage/sharedfileset.h +37 -0
  347. data/ext/pg_query/include/postgres/storage/shm_mq.h +86 -0
  348. data/ext/pg_query/include/postgres/storage/shm_toc.h +58 -0
  349. data/ext/pg_query/include/postgres/storage/shmem.h +59 -0
  350. data/ext/pg_query/include/postgres/storage/sinval.h +153 -0
  351. data/ext/pg_query/include/postgres/storage/smgr.h +127 -0
  352. data/ext/pg_query/include/postgres/storage/spin.h +77 -0
  353. data/ext/pg_query/include/postgres/storage/standby.h +109 -0
  354. data/ext/pg_query/include/postgres/storage/standbydefs.h +74 -0
  355. data/ext/pg_query/include/postgres/storage/sync.h +66 -0
  356. data/ext/pg_query/include/postgres/tcop/cmdtag.h +62 -0
  357. data/ext/pg_query/include/postgres/tcop/cmdtaglist.h +219 -0
  358. data/ext/pg_query/include/postgres/tcop/deparse_utility.h +108 -0
  359. data/ext/pg_query/include/postgres/tcop/dest.h +148 -0
  360. data/ext/pg_query/include/postgres/tcop/fastpath.h +20 -0
  361. data/ext/pg_query/include/postgres/tcop/pquery.h +51 -0
  362. data/ext/pg_query/include/postgres/tcop/tcopprot.h +98 -0
  363. data/ext/pg_query/include/postgres/tcop/utility.h +112 -0
  364. data/ext/pg_query/include/postgres/tsearch/ts_cache.h +96 -0
  365. data/ext/pg_query/include/postgres/utils/acl.h +290 -0
  366. data/ext/pg_query/include/postgres/utils/aclchk_internal.h +45 -0
  367. data/ext/pg_query/include/postgres/utils/array.h +481 -0
  368. data/ext/pg_query/include/postgres/utils/ascii.h +84 -0
  369. data/ext/pg_query/include/postgres/utils/backend_progress.h +46 -0
  370. data/ext/pg_query/include/postgres/utils/backend_status.h +340 -0
  371. data/ext/pg_query/include/postgres/utils/builtins.h +139 -0
  372. data/ext/pg_query/include/postgres/utils/bytea.h +28 -0
  373. data/ext/pg_query/include/postgres/utils/catcache.h +230 -0
  374. data/ext/pg_query/include/postgres/utils/date.h +118 -0
  375. data/ext/pg_query/include/postgres/utils/datetime.h +367 -0
  376. data/ext/pg_query/include/postgres/utils/datum.h +76 -0
  377. data/ext/pg_query/include/postgres/utils/dsa.h +166 -0
  378. data/ext/pg_query/include/postgres/utils/elog.h +540 -0
  379. data/ext/pg_query/include/postgres/utils/errcodes.h +352 -0
  380. data/ext/pg_query/include/postgres/utils/expandeddatum.h +170 -0
  381. data/ext/pg_query/include/postgres/utils/expandedrecord.h +241 -0
  382. data/ext/pg_query/include/postgres/utils/float.h +357 -0
  383. data/ext/pg_query/include/postgres/utils/fmgroids.h +3347 -0
  384. data/ext/pg_query/include/postgres/utils/fmgrprotos.h +2904 -0
  385. data/ext/pg_query/include/postgres/utils/fmgrtab.h +49 -0
  386. data/ext/pg_query/include/postgres/utils/guc.h +456 -0
  387. data/ext/pg_query/include/postgres/utils/guc_hooks.h +184 -0
  388. data/ext/pg_query/include/postgres/utils/guc_tables.h +323 -0
  389. data/ext/pg_query/include/postgres/utils/hsearch.h +153 -0
  390. data/ext/pg_query/include/postgres/utils/injection_point.h +44 -0
  391. data/ext/pg_query/include/postgres/utils/inval.h +68 -0
  392. data/ext/pg_query/include/postgres/utils/logtape.h +77 -0
  393. data/ext/pg_query/include/postgres/utils/lsyscache.h +215 -0
  394. data/ext/pg_query/include/postgres/utils/memdebug.h +82 -0
  395. data/ext/pg_query/include/postgres/utils/memutils.h +193 -0
  396. data/ext/pg_query/include/postgres/utils/memutils_internal.h +176 -0
  397. data/ext/pg_query/include/postgres/utils/memutils_memorychunk.h +253 -0
  398. data/ext/pg_query/include/postgres/utils/numeric.h +110 -0
  399. data/ext/pg_query/include/postgres/utils/palloc.h +151 -0
  400. data/ext/pg_query/include/postgres/utils/partcache.h +103 -0
  401. data/ext/pg_query/include/postgres/utils/pg_locale.h +136 -0
  402. data/ext/pg_query/include/postgres/utils/pgstat_internal.h +808 -0
  403. data/ext/pg_query/include/postgres/utils/plancache.h +238 -0
  404. data/ext/pg_query/include/postgres/utils/portal.h +252 -0
  405. data/ext/pg_query/include/postgres/utils/queryenvironment.h +74 -0
  406. data/ext/pg_query/include/postgres/utils/regproc.h +39 -0
  407. data/ext/pg_query/include/postgres/utils/rel.h +711 -0
  408. data/ext/pg_query/include/postgres/utils/relcache.h +155 -0
  409. data/ext/pg_query/include/postgres/utils/reltrigger.h +81 -0
  410. data/ext/pg_query/include/postgres/utils/resowner.h +167 -0
  411. data/ext/pg_query/include/postgres/utils/ruleutils.h +52 -0
  412. data/ext/pg_query/include/postgres/utils/sharedtuplestore.h +61 -0
  413. data/ext/pg_query/include/postgres/utils/snapmgr.h +130 -0
  414. data/ext/pg_query/include/postgres/utils/snapshot.h +219 -0
  415. data/ext/pg_query/include/postgres/utils/sortsupport.h +391 -0
  416. data/ext/pg_query/include/postgres/utils/syscache.h +131 -0
  417. data/ext/pg_query/include/postgres/utils/timeout.h +96 -0
  418. data/ext/pg_query/include/postgres/utils/timestamp.h +147 -0
  419. data/ext/pg_query/include/postgres/utils/tuplesort.h +472 -0
  420. data/ext/pg_query/include/postgres/utils/tuplestore.h +88 -0
  421. data/ext/pg_query/include/postgres/utils/typcache.h +210 -0
  422. data/ext/pg_query/include/postgres/utils/varlena.h +53 -0
  423. data/ext/pg_query/include/postgres/utils/wait_event.h +108 -0
  424. data/ext/pg_query/include/postgres/utils/wait_event_types.h +218 -0
  425. data/ext/pg_query/include/postgres/utils/xml.h +94 -0
  426. data/ext/pg_query/include/postgres/varatt.h +358 -0
  427. data/ext/pg_query/include/protobuf/pg_query.pb-c.h +1546 -792
  428. data/ext/pg_query/include/protobuf/pg_query.pb.h +58365 -46595
  429. data/ext/pg_query/pg_query.c +9 -0
  430. data/ext/pg_query/pg_query.pb-c.c +6598 -3739
  431. data/ext/pg_query/pg_query_fingerprint.c +4 -5
  432. data/ext/pg_query/pg_query_normalize.c +42 -1
  433. data/ext/pg_query/pg_query_outfuncs_json.c +9 -1
  434. data/ext/pg_query/pg_query_outfuncs_protobuf.c +1 -0
  435. data/ext/pg_query/pg_query_parse.c +1 -1
  436. data/ext/pg_query/pg_query_parse_plpgsql.c +18 -17
  437. data/ext/pg_query/pg_query_readfuncs_protobuf.c +3 -2
  438. data/ext/pg_query/pg_query_ruby.c +5 -0
  439. data/ext/pg_query/pg_query_ruby_freebsd.sym +0 -1
  440. data/ext/pg_query/pg_query_scan.c +1 -1
  441. data/ext/pg_query/pg_query_split.c +1 -1
  442. data/ext/pg_query/postgres_deparse.c +409 -21
  443. data/ext/pg_query/src_backend_catalog_namespace.c +241 -66
  444. data/ext/pg_query/src_backend_catalog_pg_proc.c +1 -3
  445. data/ext/pg_query/src_backend_commands_define.c +2 -3
  446. data/ext/pg_query/src_backend_nodes_bitmapset.c +137 -94
  447. data/ext/pg_query/src_backend_nodes_copyfuncs.c +1 -1
  448. data/ext/pg_query/src_backend_nodes_equalfuncs.c +1 -1
  449. data/ext/pg_query/src_backend_nodes_extensible.c +1 -1
  450. data/ext/pg_query/src_backend_nodes_list.c +3 -7
  451. data/ext/pg_query/src_backend_nodes_makefuncs.c +59 -20
  452. data/ext/pg_query/src_backend_nodes_nodeFuncs.c +109 -2
  453. data/ext/pg_query/src_backend_nodes_value.c +1 -1
  454. data/ext/pg_query/src_backend_parser_gram.c +34490 -32135
  455. data/ext/pg_query/src_backend_parser_parser.c +8 -8
  456. data/ext/pg_query/src_backend_parser_scan.c +5637 -3028
  457. data/ext/pg_query/src_backend_parser_scansup.c +2 -1
  458. data/ext/pg_query/src_backend_storage_ipc_ipc.c +1 -1
  459. data/ext/pg_query/src_backend_tcop_postgres.c +34 -10
  460. data/ext/pg_query/src_backend_utils_activity_pgstat_database.c +2 -2
  461. data/ext/pg_query/src_backend_utils_adt_datum.c +8 -6
  462. data/ext/pg_query/src_backend_utils_adt_expandeddatum.c +1 -1
  463. data/ext/pg_query/src_backend_utils_adt_format_type.c +1 -1
  464. data/ext/pg_query/src_backend_utils_adt_numutils.c +4 -5
  465. data/ext/pg_query/src_backend_utils_adt_ruleutils.c +101 -28
  466. data/ext/pg_query/src_backend_utils_error_assert.c +1 -1
  467. data/ext/pg_query/src_backend_utils_error_elog.c +60 -190
  468. data/ext/pg_query/src_backend_utils_fmgr_fmgr.c +4 -2
  469. data/ext/pg_query/src_backend_utils_init_globals.c +16 -4
  470. data/ext/pg_query/src_backend_utils_mb_mbutils.c +19 -81
  471. data/ext/pg_query/src_backend_utils_misc_guc_tables.c +16 -8
  472. data/ext/pg_query/src_backend_utils_mmgr_alignedalloc.c +8 -5
  473. data/ext/pg_query/src_backend_utils_mmgr_aset.c +308 -238
  474. data/ext/pg_query/src_backend_utils_mmgr_bump.c +728 -0
  475. data/ext/pg_query/src_backend_utils_mmgr_generation.c +273 -197
  476. data/ext/pg_query/src_backend_utils_mmgr_mcxt.c +270 -215
  477. data/ext/pg_query/src_backend_utils_mmgr_slab.c +154 -96
  478. data/ext/pg_query/src_common_encnames.c +43 -44
  479. data/ext/pg_query/src_common_hashfn.c +1 -1
  480. data/ext/pg_query/src_common_keywords.c +1 -1
  481. data/ext/pg_query/src_common_kwlist_d.h +511 -466
  482. data/ext/pg_query/src_common_kwlookup.c +1 -1
  483. data/ext/pg_query/src_common_psprintf.c +3 -3
  484. data/ext/pg_query/src_common_stringinfo.c +18 -1
  485. data/ext/pg_query/src_common_wchar.c +45 -108
  486. data/ext/pg_query/src_pl_plpgsql_src_pl_comp.c +99 -5
  487. data/ext/pg_query/src_pl_plpgsql_src_pl_funcs.c +1 -1
  488. data/ext/pg_query/src_pl_plpgsql_src_pl_gram.c +242 -143
  489. data/ext/pg_query/src_pl_plpgsql_src_pl_handler.c +1 -1
  490. data/ext/pg_query/src_pl_plpgsql_src_pl_reserved_kwlist_d.h +1 -1
  491. data/ext/pg_query/src_pl_plpgsql_src_pl_scanner.c +19 -1
  492. data/ext/pg_query/src_pl_plpgsql_src_pl_unreserved_kwlist_d.h +1 -1
  493. data/ext/pg_query/src_port_pg_bitutils.c +251 -32
  494. data/ext/pg_query/src_port_pgstrcasecmp.c +29 -1
  495. data/ext/pg_query/src_port_snprintf.c +4 -4
  496. data/ext/pg_query/src_port_strerror.c +1 -3
  497. data/ext/pg_query/src_port_strlcpy.c +79 -0
  498. data/lib/pg_query/fingerprint.rb +2 -3
  499. data/lib/pg_query/node.rb +16 -11
  500. data/lib/pg_query/param_refs.rb +1 -1
  501. data/lib/pg_query/parse.rb +1 -1
  502. data/lib/pg_query/pg_query_pb.rb +26 -3
  503. data/lib/pg_query/treewalker.rb +52 -12
  504. data/lib/pg_query/truncate.rb +1 -1
  505. data/lib/pg_query/version.rb +1 -1
  506. metadata +444 -400
  507. data/ext/pg_query/guc-file.c +0 -0
  508. data/ext/pg_query/include/access/amapi.h +0 -292
  509. data/ext/pg_query/include/access/attmap.h +0 -54
  510. data/ext/pg_query/include/access/attnum.h +0 -64
  511. data/ext/pg_query/include/access/clog.h +0 -63
  512. data/ext/pg_query/include/access/commit_ts.h +0 -74
  513. data/ext/pg_query/include/access/detoast.h +0 -82
  514. data/ext/pg_query/include/access/genam.h +0 -233
  515. data/ext/pg_query/include/access/gin.h +0 -91
  516. data/ext/pg_query/include/access/htup.h +0 -89
  517. data/ext/pg_query/include/access/htup_details.h +0 -811
  518. data/ext/pg_query/include/access/itup.h +0 -170
  519. data/ext/pg_query/include/access/parallel.h +0 -82
  520. data/ext/pg_query/include/access/printtup.h +0 -35
  521. data/ext/pg_query/include/access/relation.h +0 -28
  522. data/ext/pg_query/include/access/relscan.h +0 -191
  523. data/ext/pg_query/include/access/rmgrlist.h +0 -49
  524. data/ext/pg_query/include/access/sdir.h +0 -67
  525. data/ext/pg_query/include/access/skey.h +0 -151
  526. data/ext/pg_query/include/access/stratnum.h +0 -85
  527. data/ext/pg_query/include/access/sysattr.h +0 -29
  528. data/ext/pg_query/include/access/table.h +0 -28
  529. data/ext/pg_query/include/access/tableam.h +0 -2100
  530. data/ext/pg_query/include/access/toast_compression.h +0 -73
  531. data/ext/pg_query/include/access/transam.h +0 -375
  532. data/ext/pg_query/include/access/tsmapi.h +0 -82
  533. data/ext/pg_query/include/access/tupconvert.h +0 -54
  534. data/ext/pg_query/include/access/tupdesc.h +0 -154
  535. data/ext/pg_query/include/access/tupmacs.h +0 -207
  536. data/ext/pg_query/include/access/twophase.h +0 -65
  537. data/ext/pg_query/include/access/xact.h +0 -530
  538. data/ext/pg_query/include/access/xlog.h +0 -302
  539. data/ext/pg_query/include/access/xlog_internal.h +0 -404
  540. data/ext/pg_query/include/access/xlogbackup.h +0 -41
  541. data/ext/pg_query/include/access/xlogdefs.h +0 -82
  542. data/ext/pg_query/include/access/xlogprefetcher.h +0 -55
  543. data/ext/pg_query/include/access/xlogreader.h +0 -444
  544. data/ext/pg_query/include/access/xlogrecord.h +0 -248
  545. data/ext/pg_query/include/access/xlogrecovery.h +0 -158
  546. data/ext/pg_query/include/archive/archive_module.h +0 -59
  547. data/ext/pg_query/include/c.h +0 -1379
  548. data/ext/pg_query/include/catalog/catalog.h +0 -45
  549. data/ext/pg_query/include/catalog/catversion.h +0 -62
  550. data/ext/pg_query/include/catalog/dependency.h +0 -270
  551. data/ext/pg_query/include/catalog/genbki.h +0 -143
  552. data/ext/pg_query/include/catalog/index.h +0 -214
  553. data/ext/pg_query/include/catalog/indexing.h +0 -54
  554. data/ext/pg_query/include/catalog/namespace.h +0 -190
  555. data/ext/pg_query/include/catalog/objectaccess.h +0 -267
  556. data/ext/pg_query/include/catalog/objectaddress.h +0 -89
  557. data/ext/pg_query/include/catalog/pg_aggregate.h +0 -180
  558. data/ext/pg_query/include/catalog/pg_aggregate_d.h +0 -78
  559. data/ext/pg_query/include/catalog/pg_am.h +0 -63
  560. data/ext/pg_query/include/catalog/pg_am_d.h +0 -47
  561. data/ext/pg_query/include/catalog/pg_attribute.h +0 -223
  562. data/ext/pg_query/include/catalog/pg_attribute_d.h +0 -62
  563. data/ext/pg_query/include/catalog/pg_authid.h +0 -63
  564. data/ext/pg_query/include/catalog/pg_authid_d.h +0 -59
  565. data/ext/pg_query/include/catalog/pg_class.h +0 -230
  566. data/ext/pg_query/include/catalog/pg_class_d.h +0 -132
  567. data/ext/pg_query/include/catalog/pg_collation.h +0 -100
  568. data/ext/pg_query/include/catalog/pg_collation_d.h +0 -63
  569. data/ext/pg_query/include/catalog/pg_constraint.h +0 -273
  570. data/ext/pg_query/include/catalog/pg_constraint_d.h +0 -73
  571. data/ext/pg_query/include/catalog/pg_control.h +0 -258
  572. data/ext/pg_query/include/catalog/pg_conversion.h +0 -75
  573. data/ext/pg_query/include/catalog/pg_conversion_d.h +0 -38
  574. data/ext/pg_query/include/catalog/pg_database.h +0 -124
  575. data/ext/pg_query/include/catalog/pg_database_d.h +0 -52
  576. data/ext/pg_query/include/catalog/pg_depend.h +0 -77
  577. data/ext/pg_query/include/catalog/pg_depend_d.h +0 -36
  578. data/ext/pg_query/include/catalog/pg_event_trigger.h +0 -57
  579. data/ext/pg_query/include/catalog/pg_event_trigger_d.h +0 -36
  580. data/ext/pg_query/include/catalog/pg_index.h +0 -90
  581. data/ext/pg_query/include/catalog/pg_index_d.h +0 -59
  582. data/ext/pg_query/include/catalog/pg_language.h +0 -72
  583. data/ext/pg_query/include/catalog/pg_language_d.h +0 -41
  584. data/ext/pg_query/include/catalog/pg_namespace.h +0 -64
  585. data/ext/pg_query/include/catalog/pg_namespace_d.h +0 -36
  586. data/ext/pg_query/include/catalog/pg_opclass.h +0 -88
  587. data/ext/pg_query/include/catalog/pg_opclass_d.h +0 -51
  588. data/ext/pg_query/include/catalog/pg_operator.h +0 -107
  589. data/ext/pg_query/include/catalog/pg_operator_d.h +0 -142
  590. data/ext/pg_query/include/catalog/pg_opfamily.h +0 -64
  591. data/ext/pg_query/include/catalog/pg_opfamily_d.h +0 -51
  592. data/ext/pg_query/include/catalog/pg_partitioned_table.h +0 -74
  593. data/ext/pg_query/include/catalog/pg_partitioned_table_d.h +0 -36
  594. data/ext/pg_query/include/catalog/pg_proc.h +0 -220
  595. data/ext/pg_query/include/catalog/pg_proc_d.h +0 -101
  596. data/ext/pg_query/include/catalog/pg_publication.h +0 -158
  597. data/ext/pg_query/include/catalog/pg_publication_d.h +0 -38
  598. data/ext/pg_query/include/catalog/pg_replication_origin.h +0 -62
  599. data/ext/pg_query/include/catalog/pg_replication_origin_d.h +0 -33
  600. data/ext/pg_query/include/catalog/pg_statistic.h +0 -282
  601. data/ext/pg_query/include/catalog/pg_statistic_d.h +0 -195
  602. data/ext/pg_query/include/catalog/pg_statistic_ext.h +0 -88
  603. data/ext/pg_query/include/catalog/pg_statistic_ext_d.h +0 -45
  604. data/ext/pg_query/include/catalog/pg_transform.h +0 -48
  605. data/ext/pg_query/include/catalog/pg_transform_d.h +0 -34
  606. data/ext/pg_query/include/catalog/pg_trigger.h +0 -153
  607. data/ext/pg_query/include/catalog/pg_trigger_d.h +0 -109
  608. data/ext/pg_query/include/catalog/pg_ts_config.h +0 -53
  609. data/ext/pg_query/include/catalog/pg_ts_config_d.h +0 -34
  610. data/ext/pg_query/include/catalog/pg_ts_dict.h +0 -59
  611. data/ext/pg_query/include/catalog/pg_ts_dict_d.h +0 -35
  612. data/ext/pg_query/include/catalog/pg_ts_parser.h +0 -60
  613. data/ext/pg_query/include/catalog/pg_ts_parser_d.h +0 -37
  614. data/ext/pg_query/include/catalog/pg_ts_template.h +0 -51
  615. data/ext/pg_query/include/catalog/pg_ts_template_d.h +0 -34
  616. data/ext/pg_query/include/catalog/pg_type.h +0 -404
  617. data/ext/pg_query/include/catalog/pg_type_d.h +0 -324
  618. data/ext/pg_query/include/catalog/storage.h +0 -50
  619. data/ext/pg_query/include/commands/async.h +0 -53
  620. data/ext/pg_query/include/commands/dbcommands.h +0 -37
  621. data/ext/pg_query/include/commands/defrem.h +0 -161
  622. data/ext/pg_query/include/commands/event_trigger.h +0 -88
  623. data/ext/pg_query/include/commands/explain.h +0 -129
  624. data/ext/pg_query/include/commands/prepare.h +0 -61
  625. data/ext/pg_query/include/commands/tablespace.h +0 -69
  626. data/ext/pg_query/include/commands/trigger.h +0 -288
  627. data/ext/pg_query/include/commands/vacuum.h +0 -386
  628. data/ext/pg_query/include/common/cryptohash.h +0 -39
  629. data/ext/pg_query/include/common/file_perm.h +0 -56
  630. data/ext/pg_query/include/common/hashfn.h +0 -104
  631. data/ext/pg_query/include/common/int.h +0 -437
  632. data/ext/pg_query/include/common/ip.h +0 -33
  633. data/ext/pg_query/include/common/keywords.h +0 -29
  634. data/ext/pg_query/include/common/kwlookup.h +0 -44
  635. data/ext/pg_query/include/common/pg_prng.h +0 -61
  636. data/ext/pg_query/include/common/relpath.h +0 -97
  637. data/ext/pg_query/include/common/scram-common.h +0 -70
  638. data/ext/pg_query/include/common/sha2.h +0 -32
  639. data/ext/pg_query/include/common/string.h +0 -44
  640. data/ext/pg_query/include/common/unicode_east_asian_fw_table.h +0 -125
  641. data/ext/pg_query/include/copyfuncs.funcs.c +0 -5013
  642. data/ext/pg_query/include/copyfuncs.switch.c +0 -938
  643. data/ext/pg_query/include/datatype/timestamp.h +0 -243
  644. data/ext/pg_query/include/equalfuncs.funcs.c +0 -3097
  645. data/ext/pg_query/include/equalfuncs.switch.c +0 -785
  646. data/ext/pg_query/include/executor/execdesc.h +0 -70
  647. data/ext/pg_query/include/executor/executor.h +0 -680
  648. data/ext/pg_query/include/executor/functions.h +0 -55
  649. data/ext/pg_query/include/executor/instrument.h +0 -118
  650. data/ext/pg_query/include/executor/spi.h +0 -213
  651. data/ext/pg_query/include/executor/tablefunc.h +0 -67
  652. data/ext/pg_query/include/executor/tuptable.h +0 -494
  653. data/ext/pg_query/include/fmgr.h +0 -800
  654. data/ext/pg_query/include/foreign/fdwapi.h +0 -294
  655. data/ext/pg_query/include/funcapi.h +0 -360
  656. data/ext/pg_query/include/gram.h +0 -1127
  657. data/ext/pg_query/include/gramparse.h +0 -75
  658. data/ext/pg_query/include/jit/jit.h +0 -105
  659. data/ext/pg_query/include/kwlist_d.h +0 -1119
  660. data/ext/pg_query/include/lib/dshash.h +0 -115
  661. data/ext/pg_query/include/lib/ilist.h +0 -1159
  662. data/ext/pg_query/include/lib/pairingheap.h +0 -102
  663. data/ext/pg_query/include/lib/simplehash.h +0 -1184
  664. data/ext/pg_query/include/lib/sort_template.h +0 -432
  665. data/ext/pg_query/include/lib/stringinfo.h +0 -161
  666. data/ext/pg_query/include/libpq/auth.h +0 -37
  667. data/ext/pg_query/include/libpq/crypt.h +0 -47
  668. data/ext/pg_query/include/libpq/hba.h +0 -186
  669. data/ext/pg_query/include/libpq/libpq-be.h +0 -354
  670. data/ext/pg_query/include/libpq/libpq.h +0 -144
  671. data/ext/pg_query/include/libpq/pqcomm.h +0 -163
  672. data/ext/pg_query/include/libpq/pqformat.h +0 -210
  673. data/ext/pg_query/include/libpq/pqsignal.h +0 -54
  674. data/ext/pg_query/include/libpq/sasl.h +0 -136
  675. data/ext/pg_query/include/libpq/scram.h +0 -37
  676. data/ext/pg_query/include/mb/pg_wchar.h +0 -772
  677. data/ext/pg_query/include/mb/stringinfo_mb.h +0 -24
  678. data/ext/pg_query/include/miscadmin.h +0 -507
  679. data/ext/pg_query/include/nodes/bitmapset.h +0 -126
  680. data/ext/pg_query/include/nodes/execnodes.h +0 -2768
  681. data/ext/pg_query/include/nodes/extensible.h +0 -164
  682. data/ext/pg_query/include/nodes/lockoptions.h +0 -61
  683. data/ext/pg_query/include/nodes/makefuncs.h +0 -121
  684. data/ext/pg_query/include/nodes/memnodes.h +0 -113
  685. data/ext/pg_query/include/nodes/miscnodes.h +0 -56
  686. data/ext/pg_query/include/nodes/nodeFuncs.h +0 -222
  687. data/ext/pg_query/include/nodes/nodes.h +0 -446
  688. data/ext/pg_query/include/nodes/nodetags.h +0 -471
  689. data/ext/pg_query/include/nodes/params.h +0 -170
  690. data/ext/pg_query/include/nodes/parsenodes.h +0 -4050
  691. data/ext/pg_query/include/nodes/pathnodes.h +0 -3384
  692. data/ext/pg_query/include/nodes/pg_list.h +0 -635
  693. data/ext/pg_query/include/nodes/plannodes.h +0 -1592
  694. data/ext/pg_query/include/nodes/primnodes.h +0 -2041
  695. data/ext/pg_query/include/nodes/print.h +0 -34
  696. data/ext/pg_query/include/nodes/queryjumble.h +0 -86
  697. data/ext/pg_query/include/nodes/replnodes.h +0 -111
  698. data/ext/pg_query/include/nodes/supportnodes.h +0 -346
  699. data/ext/pg_query/include/nodes/tidbitmap.h +0 -75
  700. data/ext/pg_query/include/nodes/value.h +0 -90
  701. data/ext/pg_query/include/optimizer/cost.h +0 -215
  702. data/ext/pg_query/include/optimizer/geqo.h +0 -90
  703. data/ext/pg_query/include/optimizer/geqo_gene.h +0 -45
  704. data/ext/pg_query/include/optimizer/optimizer.h +0 -202
  705. data/ext/pg_query/include/optimizer/paths.h +0 -266
  706. data/ext/pg_query/include/optimizer/planmain.h +0 -117
  707. data/ext/pg_query/include/parser/analyze.h +0 -64
  708. data/ext/pg_query/include/parser/kwlist.h +0 -498
  709. data/ext/pg_query/include/parser/parse_agg.h +0 -65
  710. data/ext/pg_query/include/parser/parse_coerce.h +0 -102
  711. data/ext/pg_query/include/parser/parse_expr.h +0 -25
  712. data/ext/pg_query/include/parser/parse_func.h +0 -74
  713. data/ext/pg_query/include/parser/parse_node.h +0 -357
  714. data/ext/pg_query/include/parser/parse_oper.h +0 -65
  715. data/ext/pg_query/include/parser/parse_relation.h +0 -129
  716. data/ext/pg_query/include/parser/parse_type.h +0 -61
  717. data/ext/pg_query/include/parser/parser.h +0 -68
  718. data/ext/pg_query/include/parser/parsetree.h +0 -61
  719. data/ext/pg_query/include/parser/scanner.h +0 -152
  720. data/ext/pg_query/include/parser/scansup.h +0 -27
  721. data/ext/pg_query/include/partitioning/partdefs.h +0 -26
  722. data/ext/pg_query/include/pg_config.h +0 -843
  723. data/ext/pg_query/include/pg_config_manual.h +0 -372
  724. data/ext/pg_query/include/pg_config_os.h +0 -8
  725. data/ext/pg_query/include/pg_getopt.h +0 -56
  726. data/ext/pg_query/include/pg_trace.h +0 -17
  727. data/ext/pg_query/include/pgstat.h +0 -778
  728. data/ext/pg_query/include/pgtime.h +0 -94
  729. data/ext/pg_query/include/pl_gram.h +0 -385
  730. data/ext/pg_query/include/pl_reserved_kwlist.h +0 -52
  731. data/ext/pg_query/include/pl_reserved_kwlist_d.h +0 -114
  732. data/ext/pg_query/include/pl_unreserved_kwlist.h +0 -112
  733. data/ext/pg_query/include/pl_unreserved_kwlist_d.h +0 -246
  734. data/ext/pg_query/include/plerrcodes.h +0 -998
  735. data/ext/pg_query/include/plpgsql.h +0 -1340
  736. data/ext/pg_query/include/port/atomics/arch-arm.h +0 -32
  737. data/ext/pg_query/include/port/atomics/arch-ppc.h +0 -254
  738. data/ext/pg_query/include/port/atomics/arch-x86.h +0 -252
  739. data/ext/pg_query/include/port/atomics/fallback.h +0 -170
  740. data/ext/pg_query/include/port/atomics/generic-gcc.h +0 -286
  741. data/ext/pg_query/include/port/atomics/generic.h +0 -401
  742. data/ext/pg_query/include/port/atomics.h +0 -519
  743. data/ext/pg_query/include/port/pg_bitutils.h +0 -339
  744. data/ext/pg_query/include/port/pg_bswap.h +0 -161
  745. data/ext/pg_query/include/port/pg_crc32c.h +0 -101
  746. data/ext/pg_query/include/port/simd.h +0 -375
  747. data/ext/pg_query/include/port.h +0 -520
  748. data/ext/pg_query/include/portability/instr_time.h +0 -197
  749. data/ext/pg_query/include/postgres.h +0 -579
  750. data/ext/pg_query/include/postmaster/autovacuum.h +0 -80
  751. data/ext/pg_query/include/postmaster/auxprocess.h +0 -20
  752. data/ext/pg_query/include/postmaster/bgworker.h +0 -162
  753. data/ext/pg_query/include/postmaster/bgworker_internals.h +0 -64
  754. data/ext/pg_query/include/postmaster/bgwriter.h +0 -45
  755. data/ext/pg_query/include/postmaster/fork_process.h +0 -17
  756. data/ext/pg_query/include/postmaster/interrupt.h +0 -32
  757. data/ext/pg_query/include/postmaster/pgarch.h +0 -36
  758. data/ext/pg_query/include/postmaster/postmaster.h +0 -81
  759. data/ext/pg_query/include/postmaster/startup.h +0 -41
  760. data/ext/pg_query/include/postmaster/syslogger.h +0 -103
  761. data/ext/pg_query/include/postmaster/walwriter.h +0 -23
  762. data/ext/pg_query/include/regex/regex.h +0 -189
  763. data/ext/pg_query/include/replication/logicallauncher.h +0 -34
  764. data/ext/pg_query/include/replication/logicalproto.h +0 -274
  765. data/ext/pg_query/include/replication/logicalworker.h +0 -32
  766. data/ext/pg_query/include/replication/origin.h +0 -73
  767. data/ext/pg_query/include/replication/reorderbuffer.h +0 -753
  768. data/ext/pg_query/include/replication/slot.h +0 -249
  769. data/ext/pg_query/include/replication/syncrep.h +0 -109
  770. data/ext/pg_query/include/replication/walreceiver.h +0 -478
  771. data/ext/pg_query/include/replication/walsender.h +0 -74
  772. data/ext/pg_query/include/rewrite/prs2lock.h +0 -46
  773. data/ext/pg_query/include/rewrite/rewriteHandler.h +0 -35
  774. data/ext/pg_query/include/rewrite/rewriteManip.h +0 -96
  775. data/ext/pg_query/include/rewrite/rewriteSupport.h +0 -26
  776. data/ext/pg_query/include/src_backend_nodes_copyfuncs.funcs.c +0 -5321
  777. data/ext/pg_query/include/src_backend_nodes_equalfuncs.funcs.c +0 -3354
  778. data/ext/pg_query/include/storage/backendid.h +0 -37
  779. data/ext/pg_query/include/storage/block.h +0 -108
  780. data/ext/pg_query/include/storage/buf.h +0 -46
  781. data/ext/pg_query/include/storage/bufmgr.h +0 -393
  782. data/ext/pg_query/include/storage/bufpage.h +0 -510
  783. data/ext/pg_query/include/storage/condition_variable.h +0 -73
  784. data/ext/pg_query/include/storage/dsm.h +0 -61
  785. data/ext/pg_query/include/storage/dsm_impl.h +0 -79
  786. data/ext/pg_query/include/storage/fd.h +0 -202
  787. data/ext/pg_query/include/storage/fileset.h +0 -40
  788. data/ext/pg_query/include/storage/ipc.h +0 -84
  789. data/ext/pg_query/include/storage/item.h +0 -19
  790. data/ext/pg_query/include/storage/itemid.h +0 -184
  791. data/ext/pg_query/include/storage/itemptr.h +0 -245
  792. data/ext/pg_query/include/storage/large_object.h +0 -100
  793. data/ext/pg_query/include/storage/latch.h +0 -194
  794. data/ext/pg_query/include/storage/lmgr.h +0 -120
  795. data/ext/pg_query/include/storage/lock.h +0 -624
  796. data/ext/pg_query/include/storage/lockdefs.h +0 -59
  797. data/ext/pg_query/include/storage/lwlock.h +0 -220
  798. data/ext/pg_query/include/storage/lwlocknames.h +0 -50
  799. data/ext/pg_query/include/storage/off.h +0 -57
  800. data/ext/pg_query/include/storage/pg_sema.h +0 -61
  801. data/ext/pg_query/include/storage/pg_shmem.h +0 -92
  802. data/ext/pg_query/include/storage/pmsignal.h +0 -105
  803. data/ext/pg_query/include/storage/predicate.h +0 -87
  804. data/ext/pg_query/include/storage/proc.h +0 -466
  805. data/ext/pg_query/include/storage/procarray.h +0 -99
  806. data/ext/pg_query/include/storage/proclist_types.h +0 -51
  807. data/ext/pg_query/include/storage/procsignal.h +0 -73
  808. data/ext/pg_query/include/storage/relfilelocator.h +0 -99
  809. data/ext/pg_query/include/storage/s_lock.h +0 -867
  810. data/ext/pg_query/include/storage/sharedfileset.h +0 -37
  811. data/ext/pg_query/include/storage/shm_mq.h +0 -86
  812. data/ext/pg_query/include/storage/shm_toc.h +0 -58
  813. data/ext/pg_query/include/storage/shmem.h +0 -59
  814. data/ext/pg_query/include/storage/sinval.h +0 -153
  815. data/ext/pg_query/include/storage/sinvaladt.h +0 -45
  816. data/ext/pg_query/include/storage/smgr.h +0 -113
  817. data/ext/pg_query/include/storage/spin.h +0 -77
  818. data/ext/pg_query/include/storage/standby.h +0 -99
  819. data/ext/pg_query/include/storage/standbydefs.h +0 -74
  820. data/ext/pg_query/include/storage/sync.h +0 -66
  821. data/ext/pg_query/include/tcop/cmdtag.h +0 -63
  822. data/ext/pg_query/include/tcop/cmdtaglist.h +0 -218
  823. data/ext/pg_query/include/tcop/deparse_utility.h +0 -108
  824. data/ext/pg_query/include/tcop/dest.h +0 -147
  825. data/ext/pg_query/include/tcop/fastpath.h +0 -20
  826. data/ext/pg_query/include/tcop/pquery.h +0 -51
  827. data/ext/pg_query/include/tcop/tcopprot.h +0 -94
  828. data/ext/pg_query/include/tcop/utility.h +0 -112
  829. data/ext/pg_query/include/tsearch/ts_cache.h +0 -96
  830. data/ext/pg_query/include/utils/acl.h +0 -278
  831. data/ext/pg_query/include/utils/aclchk_internal.h +0 -45
  832. data/ext/pg_query/include/utils/array.h +0 -482
  833. data/ext/pg_query/include/utils/backend_progress.h +0 -45
  834. data/ext/pg_query/include/utils/backend_status.h +0 -342
  835. data/ext/pg_query/include/utils/builtins.h +0 -136
  836. data/ext/pg_query/include/utils/bytea.h +0 -28
  837. data/ext/pg_query/include/utils/catcache.h +0 -231
  838. data/ext/pg_query/include/utils/date.h +0 -118
  839. data/ext/pg_query/include/utils/datetime.h +0 -364
  840. data/ext/pg_query/include/utils/datum.h +0 -76
  841. data/ext/pg_query/include/utils/dsa.h +0 -127
  842. data/ext/pg_query/include/utils/elog.h +0 -545
  843. data/ext/pg_query/include/utils/errcodes.h +0 -354
  844. data/ext/pg_query/include/utils/expandeddatum.h +0 -170
  845. data/ext/pg_query/include/utils/expandedrecord.h +0 -241
  846. data/ext/pg_query/include/utils/float.h +0 -357
  847. data/ext/pg_query/include/utils/fmgroids.h +0 -3314
  848. data/ext/pg_query/include/utils/fmgrprotos.h +0 -2871
  849. data/ext/pg_query/include/utils/fmgrtab.h +0 -49
  850. data/ext/pg_query/include/utils/guc.h +0 -442
  851. data/ext/pg_query/include/utils/guc_hooks.h +0 -163
  852. data/ext/pg_query/include/utils/guc_tables.h +0 -322
  853. data/ext/pg_query/include/utils/hsearch.h +0 -153
  854. data/ext/pg_query/include/utils/inval.h +0 -68
  855. data/ext/pg_query/include/utils/logtape.h +0 -77
  856. data/ext/pg_query/include/utils/lsyscache.h +0 -212
  857. data/ext/pg_query/include/utils/memdebug.h +0 -82
  858. data/ext/pg_query/include/utils/memutils.h +0 -186
  859. data/ext/pg_query/include/utils/memutils_internal.h +0 -136
  860. data/ext/pg_query/include/utils/memutils_memorychunk.h +0 -237
  861. data/ext/pg_query/include/utils/numeric.h +0 -105
  862. data/ext/pg_query/include/utils/palloc.h +0 -165
  863. data/ext/pg_query/include/utils/partcache.h +0 -103
  864. data/ext/pg_query/include/utils/pg_locale.h +0 -135
  865. data/ext/pg_query/include/utils/pgstat_internal.h +0 -814
  866. data/ext/pg_query/include/utils/pidfile.h +0 -56
  867. data/ext/pg_query/include/utils/plancache.h +0 -236
  868. data/ext/pg_query/include/utils/portal.h +0 -252
  869. data/ext/pg_query/include/utils/queryenvironment.h +0 -74
  870. data/ext/pg_query/include/utils/regproc.h +0 -39
  871. data/ext/pg_query/include/utils/rel.h +0 -712
  872. data/ext/pg_query/include/utils/relcache.h +0 -158
  873. data/ext/pg_query/include/utils/reltrigger.h +0 -81
  874. data/ext/pg_query/include/utils/resowner.h +0 -86
  875. data/ext/pg_query/include/utils/ruleutils.h +0 -52
  876. data/ext/pg_query/include/utils/sharedtuplestore.h +0 -61
  877. data/ext/pg_query/include/utils/snapmgr.h +0 -181
  878. data/ext/pg_query/include/utils/snapshot.h +0 -219
  879. data/ext/pg_query/include/utils/sortsupport.h +0 -391
  880. data/ext/pg_query/include/utils/syscache.h +0 -227
  881. data/ext/pg_query/include/utils/timeout.h +0 -95
  882. data/ext/pg_query/include/utils/timestamp.h +0 -147
  883. data/ext/pg_query/include/utils/tuplesort.h +0 -445
  884. data/ext/pg_query/include/utils/tuplestore.h +0 -91
  885. data/ext/pg_query/include/utils/typcache.h +0 -209
  886. data/ext/pg_query/include/utils/varlena.h +0 -53
  887. data/ext/pg_query/include/utils/wait_event.h +0 -294
  888. data/ext/pg_query/include/utils/xml.h +0 -94
  889. data/ext/pg_query/include/varatt.h +0 -358
  890. data/ext/pg_query/src_backend_postmaster_postmaster.c +0 -2220
  891. data/ext/pg_query/src_port_strnlen.c +0 -39
  892. /data/ext/pg_query/include/{access → postgres/access}/rmgr.h +0 -0
  893. /data/ext/pg_query/include/{commands → postgres/commands}/user.h +0 -0
  894. /data/ext/pg_query/include/{common → postgres/common}/unicode_nonspacing_table.h +0 -0
  895. /data/ext/pg_query/include/{pg_config_ext.h → postgres/pg_config_ext.h} +0 -0
  896. /data/ext/pg_query/include/{postgres_ext.h → postgres/postgres_ext.h} +0 -0
  897. /data/ext/pg_query/include/{utils → postgres/utils}/probes.h +0 -0
  898. /data/ext/pg_query/include/{utils → postgres/utils}/ps_status.h +0 -0
@@ -1,2220 +0,0 @@
1
- /*--------------------------------------------------------------------
2
- * Symbols referenced in this file:
3
- * - ClientAuthInProgress
4
- *--------------------------------------------------------------------
5
- */
6
-
7
- /*-------------------------------------------------------------------------
8
- *
9
- * postmaster.c
10
- * This program acts as a clearing house for requests to the
11
- * POSTGRES system. Frontend programs send a startup message
12
- * to the Postmaster and the postmaster uses the info in the
13
- * message to setup a backend process.
14
- *
15
- * The postmaster also manages system-wide operations such as
16
- * startup and shutdown. The postmaster itself doesn't do those
17
- * operations, mind you --- it just forks off a subprocess to do them
18
- * at the right times. It also takes care of resetting the system
19
- * if a backend crashes.
20
- *
21
- * The postmaster process creates the shared memory and semaphore
22
- * pools during startup, but as a rule does not touch them itself.
23
- * In particular, it is not a member of the PGPROC array of backends
24
- * and so it cannot participate in lock-manager operations. Keeping
25
- * the postmaster away from shared memory operations makes it simpler
26
- * and more reliable. The postmaster is almost always able to recover
27
- * from crashes of individual backends by resetting shared memory;
28
- * if it did much with shared memory then it would be prone to crashing
29
- * along with the backends.
30
- *
31
- * When a request message is received, we now fork() immediately.
32
- * The child process performs authentication of the request, and
33
- * then becomes a backend if successful. This allows the auth code
34
- * to be written in a simple single-threaded style (as opposed to the
35
- * crufty "poor man's multitasking" code that used to be needed).
36
- * More importantly, it ensures that blockages in non-multithreaded
37
- * libraries like SSL or PAM cannot cause denial of service to other
38
- * clients.
39
- *
40
- *
41
- * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
42
- * Portions Copyright (c) 1994, Regents of the University of California
43
- *
44
- *
45
- * IDENTIFICATION
46
- * src/backend/postmaster/postmaster.c
47
- *
48
- * NOTES
49
- *
50
- * Initialization:
51
- * The Postmaster sets up shared memory data structures
52
- * for the backends.
53
- *
54
- * Synchronization:
55
- * The Postmaster shares memory with the backends but should avoid
56
- * touching shared memory, so as not to become stuck if a crashing
57
- * backend screws up locks or shared memory. Likewise, the Postmaster
58
- * should never block on messages from frontend clients.
59
- *
60
- * Garbage Collection:
61
- * The Postmaster cleans up after backends if they have an emergency
62
- * exit and/or core dump.
63
- *
64
- * Error Reporting:
65
- * Use write_stderr() only for reporting "interactive" errors
66
- * (essentially, bogus arguments on the command line). Once the
67
- * postmaster is launched, use ereport().
68
- *
69
- *-------------------------------------------------------------------------
70
- */
71
-
72
- #include "postgres.h"
73
-
74
- #include <unistd.h>
75
- #include <signal.h>
76
- #include <time.h>
77
- #include <sys/wait.h>
78
- #include <ctype.h>
79
- #include <sys/stat.h>
80
- #include <sys/socket.h>
81
- #include <fcntl.h>
82
- #include <sys/param.h>
83
- #include <netdb.h>
84
- #include <limits.h>
85
-
86
- #ifdef USE_BONJOUR
87
- #include <dns_sd.h>
88
- #endif
89
-
90
- #ifdef USE_SYSTEMD
91
- #include <systemd/sd-daemon.h>
92
- #endif
93
-
94
- #ifdef HAVE_PTHREAD_IS_THREADED_NP
95
- #include <pthread.h>
96
- #endif
97
-
98
- #include "access/transam.h"
99
- #include "access/xlog.h"
100
- #include "access/xlogrecovery.h"
101
- #include "catalog/pg_control.h"
102
- #include "common/file_perm.h"
103
- #include "common/ip.h"
104
- #include "common/pg_prng.h"
105
- #include "common/string.h"
106
- #include "lib/ilist.h"
107
- #include "libpq/auth.h"
108
- #include "libpq/libpq.h"
109
- #include "libpq/pqformat.h"
110
- #include "libpq/pqsignal.h"
111
- #include "nodes/queryjumble.h"
112
- #include "pg_getopt.h"
113
- #include "pgstat.h"
114
- #include "port/pg_bswap.h"
115
- #include "postmaster/autovacuum.h"
116
- #include "postmaster/auxprocess.h"
117
- #include "postmaster/bgworker_internals.h"
118
- #include "postmaster/fork_process.h"
119
- #include "postmaster/interrupt.h"
120
- #include "postmaster/pgarch.h"
121
- #include "postmaster/postmaster.h"
122
- #include "postmaster/syslogger.h"
123
- #include "replication/logicallauncher.h"
124
- #include "replication/walsender.h"
125
- #include "storage/fd.h"
126
- #include "storage/ipc.h"
127
- #include "storage/pg_shmem.h"
128
- #include "storage/pmsignal.h"
129
- #include "storage/proc.h"
130
- #include "tcop/tcopprot.h"
131
- #include "utils/builtins.h"
132
- #include "utils/datetime.h"
133
- #include "utils/memutils.h"
134
- #include "utils/pidfile.h"
135
- #include "utils/ps_status.h"
136
- #include "utils/timeout.h"
137
- #include "utils/timestamp.h"
138
- #include "utils/varlena.h"
139
-
140
- #ifdef EXEC_BACKEND
141
- #include "storage/spin.h"
142
- #endif
143
-
144
-
145
- /*
146
- * Possible types of a backend. Beyond being the possible bkend_type values in
147
- * struct bkend, these are OR-able request flag bits for SignalSomeChildren()
148
- * and CountChildren().
149
- */
150
- #define BACKEND_TYPE_NORMAL 0x0001 /* normal backend */
151
- #define BACKEND_TYPE_AUTOVAC 0x0002 /* autovacuum worker process */
152
- #define BACKEND_TYPE_WALSND 0x0004 /* walsender process */
153
- #define BACKEND_TYPE_BGWORKER 0x0008 /* bgworker process */
154
- #define BACKEND_TYPE_ALL 0x000F /* OR of all the above */
155
-
156
- /*
157
- * List of active backends (or child processes anyway; we don't actually
158
- * know whether a given child has become a backend or is still in the
159
- * authorization phase). This is used mainly to keep track of how many
160
- * children we have and send them appropriate signals when necessary.
161
- *
162
- * As shown in the above set of backend types, this list includes not only
163
- * "normal" client sessions, but also autovacuum workers, walsenders, and
164
- * background workers. (Note that at the time of launch, walsenders are
165
- * labeled BACKEND_TYPE_NORMAL; we relabel them to BACKEND_TYPE_WALSND
166
- * upon noticing they've changed their PMChildFlags entry. Hence that check
167
- * must be done before any operation that needs to distinguish walsenders
168
- * from normal backends.)
169
- *
170
- * Also, "dead_end" children are in it: these are children launched just for
171
- * the purpose of sending a friendly rejection message to a would-be client.
172
- * We must track them because they are attached to shared memory, but we know
173
- * they will never become live backends. dead_end children are not assigned a
174
- * PMChildSlot. dead_end children have bkend_type NORMAL.
175
- *
176
- * "Special" children such as the startup, bgwriter and autovacuum launcher
177
- * tasks are not in this list. They are tracked via StartupPID and other
178
- * pid_t variables below. (Thus, there can't be more than one of any given
179
- * "special" child process type. We use BackendList entries for any child
180
- * process there can be more than one of.)
181
- */
182
- typedef struct bkend
183
- {
184
- pid_t pid; /* process id of backend */
185
- int32 cancel_key; /* cancel key for cancels for this backend */
186
- int child_slot; /* PMChildSlot for this backend, if any */
187
- int bkend_type; /* child process flavor, see above */
188
- bool dead_end; /* is it going to send an error and quit? */
189
- bool bgworker_notify; /* gets bgworker start/stop notifications */
190
- dlist_node elem; /* list link in BackendList */
191
- } Backend;
192
-
193
-
194
-
195
- #ifdef EXEC_BACKEND
196
- static Backend *ShmemBackendArray;
197
- #endif
198
-
199
-
200
-
201
-
202
-
203
- /* The socket number we are listening for connections on */
204
-
205
-
206
- /* The directory names for Unix socket(s) */
207
-
208
-
209
- /* The TCP listen address(es) */
210
-
211
-
212
- /*
213
- * SuperuserReservedConnections is the number of backends reserved for
214
- * superuser use, and ReservedConnections is the number of backends reserved
215
- * for use by roles with privileges of the pg_use_reserved_connections
216
- * predefined role. These are taken out of the pool of MaxConnections backend
217
- * slots, so the number of backend slots available for roles that are neither
218
- * superuser nor have privileges of pg_use_reserved_connections is
219
- * (MaxConnections - SuperuserReservedConnections - ReservedConnections).
220
- *
221
- * If the number of remaining slots is less than or equal to
222
- * SuperuserReservedConnections, only superusers can make new connections. If
223
- * the number of remaining slots is greater than SuperuserReservedConnections
224
- * but less than or equal to
225
- * (SuperuserReservedConnections + ReservedConnections), only superusers and
226
- * roles with privileges of pg_use_reserved_connections can make new
227
- * connections. Note that pre-existing superuser and
228
- * pg_use_reserved_connections connections don't count against the limits.
229
- */
230
-
231
-
232
-
233
- /* The socket(s) we're listening to. */
234
- #define MAXLISTEN 64
235
-
236
-
237
- /* still more option variables */
238
-
239
-
240
-
241
-
242
-
243
- /* for ps display and logging */
244
-
245
-
246
-
247
-
248
-
249
-
250
-
251
-
252
-
253
-
254
- /* PIDs of special child processes; 0 when not running */
255
-
256
-
257
-
258
-
259
-
260
-
261
-
262
-
263
-
264
- /* Startup process's status */
265
- typedef enum
266
- {
267
- STARTUP_NOT_RUNNING,
268
- STARTUP_RUNNING,
269
- STARTUP_SIGNALED, /* we sent it a SIGQUIT or SIGKILL */
270
- STARTUP_CRASHED
271
- } StartupStatusEnum;
272
-
273
-
274
-
275
- /* Startup/shutdown state */
276
- #define NoShutdown 0
277
- #define SmartShutdown 1
278
- #define FastShutdown 2
279
- #define ImmediateShutdown 3
280
-
281
-
282
-
283
- /* T if recovering from backend crash */
284
-
285
- /*
286
- * We use a simple state machine to control startup, shutdown, and
287
- * crash recovery (which is rather like shutdown followed by startup).
288
- *
289
- * After doing all the postmaster initialization work, we enter PM_STARTUP
290
- * state and the startup process is launched. The startup process begins by
291
- * reading the control file and other preliminary initialization steps.
292
- * In a normal startup, or after crash recovery, the startup process exits
293
- * with exit code 0 and we switch to PM_RUN state. However, archive recovery
294
- * is handled specially since it takes much longer and we would like to support
295
- * hot standby during archive recovery.
296
- *
297
- * When the startup process is ready to start archive recovery, it signals the
298
- * postmaster, and we switch to PM_RECOVERY state. The background writer and
299
- * checkpointer are launched, while the startup process continues applying WAL.
300
- * If Hot Standby is enabled, then, after reaching a consistent point in WAL
301
- * redo, startup process signals us again, and we switch to PM_HOT_STANDBY
302
- * state and begin accepting connections to perform read-only queries. When
303
- * archive recovery is finished, the startup process exits with exit code 0
304
- * and we switch to PM_RUN state.
305
- *
306
- * Normal child backends can only be launched when we are in PM_RUN or
307
- * PM_HOT_STANDBY state. (connsAllowed can also restrict launching.)
308
- * In other states we handle connection requests by launching "dead_end"
309
- * child processes, which will simply send the client an error message and
310
- * quit. (We track these in the BackendList so that we can know when they
311
- * are all gone; this is important because they're still connected to shared
312
- * memory, and would interfere with an attempt to destroy the shmem segment,
313
- * possibly leading to SHMALL failure when we try to make a new one.)
314
- * In PM_WAIT_DEAD_END state we are waiting for all the dead_end children
315
- * to drain out of the system, and therefore stop accepting connection
316
- * requests at all until the last existing child has quit (which hopefully
317
- * will not be very long).
318
- *
319
- * Notice that this state variable does not distinguish *why* we entered
320
- * states later than PM_RUN --- Shutdown and FatalError must be consulted
321
- * to find that out. FatalError is never true in PM_RECOVERY, PM_HOT_STANDBY,
322
- * or PM_RUN states, nor in PM_SHUTDOWN states (because we don't enter those
323
- * states when trying to recover from a crash). It can be true in PM_STARTUP
324
- * state, because we don't clear it until we've successfully started WAL redo.
325
- */
326
- typedef enum
327
- {
328
- PM_INIT, /* postmaster starting */
329
- PM_STARTUP, /* waiting for startup subprocess */
330
- PM_RECOVERY, /* in archive recovery mode */
331
- PM_HOT_STANDBY, /* in hot standby mode */
332
- PM_RUN, /* normal "database is alive" state */
333
- PM_STOP_BACKENDS, /* need to stop remaining backends */
334
- PM_WAIT_BACKENDS, /* waiting for live backends to exit */
335
- PM_SHUTDOWN, /* waiting for checkpointer to do shutdown
336
- * ckpt */
337
- PM_SHUTDOWN_2, /* waiting for archiver and walsenders to
338
- * finish */
339
- PM_WAIT_DEAD_END, /* waiting for dead_end children to exit */
340
- PM_NO_CHILDREN /* all important children have exited */
341
- } PMState;
342
-
343
-
344
-
345
- /*
346
- * While performing a "smart shutdown", we restrict new connections but stay
347
- * in PM_RUN or PM_HOT_STANDBY state until all the client backends are gone.
348
- * connsAllowed is a sub-state indicator showing the active restriction.
349
- * It is of no interest unless pmState is PM_RUN or PM_HOT_STANDBY.
350
- */
351
-
352
-
353
- /* Start time of SIGKILL timeout during immediate shutdown or child crash */
354
- /* Zero means timeout is not running */
355
-
356
-
357
- /* Length of said timeout */
358
- #define SIGKILL_CHILDREN_AFTER_SECS 5
359
-
360
- /* T if we've reached PM_RUN */
361
-
362
- __thread bool ClientAuthInProgress = false;
363
- /* T during new-client
364
- * authentication */
365
-
366
- /* stderr redirected for syslogger? */
367
-
368
- /* received START_AUTOVAC_LAUNCHER signal */
369
-
370
-
371
- /* the launcher needs to be signaled to communicate some condition */
372
-
373
-
374
- /* received START_WALRECEIVER signal */
375
-
376
-
377
- /* set when there's a worker that needs to be started up */
378
-
379
-
380
-
381
- /* set when signals arrive */
382
-
383
-
384
-
385
-
386
-
387
-
388
-
389
- /* event multiplexing object */
390
-
391
-
392
- #ifdef USE_SSL
393
- /* Set when and if SSL has been initialized properly */
394
- static bool LoadedSSL = false;
395
- #endif
396
-
397
- #ifdef USE_BONJOUR
398
- static DNSServiceRef bonjour_sdref = NULL;
399
- #endif
400
-
401
- /*
402
- * postmaster.c - function prototypes
403
- */
404
- static void CloseServerPorts(int status, Datum arg);
405
- static void unlink_external_pid_file(int status, Datum arg);
406
- static void getInstallationPaths(const char *argv0);
407
- static void checkControlFile(void);
408
- static Port *ConnCreate(int serverFd);
409
- static void ConnFree(Port *port);
410
- static void handle_pm_pmsignal_signal(SIGNAL_ARGS);
411
- static void handle_pm_child_exit_signal(SIGNAL_ARGS);
412
- static void handle_pm_reload_request_signal(SIGNAL_ARGS);
413
- static void handle_pm_shutdown_request_signal(SIGNAL_ARGS);
414
- static void process_pm_pmsignal(void);
415
- static void process_pm_child_exit(void);
416
- static void process_pm_reload_request(void);
417
- static void process_pm_shutdown_request(void);
418
- static void process_startup_packet_die(SIGNAL_ARGS);
419
- static void dummy_handler(SIGNAL_ARGS);
420
- static void StartupPacketTimeoutHandler(void);
421
- static void CleanupBackend(int pid, int exitstatus);
422
- static bool CleanupBackgroundWorker(int pid, int exitstatus);
423
- static void HandleChildCrash(int pid, int exitstatus, const char *procname);
424
- static void LogChildExit(int lev, const char *procname,
425
- int pid, int exitstatus);
426
- static void PostmasterStateMachine(void);
427
- static void BackendInitialize(Port *port);
428
- static void BackendRun(Port *port) pg_attribute_noreturn();
429
- static void ExitPostmaster(int status) pg_attribute_noreturn();
430
- static int ServerLoop(void);
431
- static int BackendStartup(Port *port);
432
- static int ProcessStartupPacket(Port *port, bool ssl_done, bool gss_done);
433
- static void SendNegotiateProtocolVersion(List *unrecognized_protocol_options);
434
- static void processCancelRequest(Port *port, void *pkt);
435
- static void report_fork_failure_to_client(Port *port, int errnum);
436
- static CAC_state canAcceptConnections(int backend_type);
437
- static bool RandomCancelKey(int32 *cancel_key);
438
- static void signal_child(pid_t pid, int signal);
439
- static void sigquit_child(pid_t pid);
440
- static bool SignalSomeChildren(int signal, int target);
441
- static void TerminateChildren(int signal);
442
-
443
- #define SignalChildren(sig) SignalSomeChildren(sig, BACKEND_TYPE_ALL)
444
-
445
- static int CountChildren(int target);
446
- static bool assign_backendlist_entry(RegisteredBgWorker *rw);
447
- static void maybe_start_bgworkers(void);
448
- static bool CreateOptsFile(int argc, char *argv[], char *fullprogname);
449
- static pid_t StartChildProcess(AuxProcType type);
450
- static void StartAutovacuumWorker(void);
451
- static void MaybeStartWalReceiver(void);
452
- static void InitPostmasterDeathWatchHandle(void);
453
-
454
- /*
455
- * Archiver is allowed to start up at the current postmaster state?
456
- *
457
- * If WAL archiving is enabled always, we are allowed to start archiver
458
- * even during recovery.
459
- */
460
- #define PgArchStartupAllowed() \
461
- (((XLogArchivingActive() && pmState == PM_RUN) || \
462
- (XLogArchivingAlways() && \
463
- (pmState == PM_RECOVERY || pmState == PM_HOT_STANDBY))) && \
464
- PgArchCanRestart())
465
-
466
- #ifdef EXEC_BACKEND
467
-
468
- #ifdef WIN32
469
- #define WNOHANG 0 /* ignored, so any integer value will do */
470
-
471
- static pid_t waitpid(pid_t pid, int *exitstatus, int options);
472
- static void WINAPI pgwin32_deadchild_callback(PVOID lpParameter, BOOLEAN TimerOrWaitFired);
473
-
474
- static HANDLE win32ChildQueue;
475
-
476
- typedef struct
477
- {
478
- HANDLE waitHandle;
479
- HANDLE procHandle;
480
- DWORD procId;
481
- } win32_deadchild_waitinfo;
482
- #endif /* WIN32 */
483
-
484
- static pid_t backend_forkexec(Port *port);
485
- static pid_t internal_forkexec(int argc, char *argv[], Port *port);
486
-
487
- /* Type for a socket that can be inherited to a client process */
488
- #ifdef WIN32
489
- typedef struct
490
- {
491
- SOCKET origsocket; /* Original socket value, or PGINVALID_SOCKET
492
- * if not a socket */
493
- WSAPROTOCOL_INFO wsainfo;
494
- } InheritableSocket;
495
- #else
496
- typedef int InheritableSocket;
497
- #endif
498
-
499
- /*
500
- * Structure contains all variables passed to exec:ed backends
501
- */
502
- typedef struct
503
- {
504
- Port port;
505
- InheritableSocket portsocket;
506
- char DataDir[MAXPGPATH];
507
- pgsocket ListenSocket[MAXLISTEN];
508
- int32 MyCancelKey;
509
- int MyPMChildSlot;
510
- #ifndef WIN32
511
- unsigned long UsedShmemSegID;
512
- #else
513
- void *ShmemProtectiveRegion;
514
- HANDLE UsedShmemSegID;
515
- #endif
516
- void *UsedShmemSegAddr;
517
- slock_t *ShmemLock;
518
- VariableCache ShmemVariableCache;
519
- Backend *ShmemBackendArray;
520
- #ifndef HAVE_SPINLOCKS
521
- PGSemaphore *SpinlockSemaArray;
522
- #endif
523
- int NamedLWLockTrancheRequests;
524
- NamedLWLockTranche *NamedLWLockTrancheArray;
525
- LWLockPadded *MainLWLockArray;
526
- slock_t *ProcStructLock;
527
- PROC_HDR *ProcGlobal;
528
- PGPROC *AuxiliaryProcs;
529
- PGPROC *PreparedXactProcs;
530
- PMSignalData *PMSignalState;
531
- pid_t PostmasterPid;
532
- TimestampTz PgStartTime;
533
- TimestampTz PgReloadTime;
534
- pg_time_t first_syslogger_file_time;
535
- bool redirection_done;
536
- bool IsBinaryUpgrade;
537
- bool query_id_enabled;
538
- int max_safe_fds;
539
- int MaxBackends;
540
- #ifdef WIN32
541
- HANDLE PostmasterHandle;
542
- HANDLE initial_signal_pipe;
543
- HANDLE syslogPipe[2];
544
- #else
545
- int postmaster_alive_fds[2];
546
- int syslogPipe[2];
547
- #endif
548
- char my_exec_path[MAXPGPATH];
549
- char pkglib_path[MAXPGPATH];
550
- } BackendParameters;
551
-
552
- static void read_backend_variables(char *id, Port *port);
553
- static void restore_backend_variables(BackendParameters *param, Port *port);
554
-
555
- #ifndef WIN32
556
- static bool save_backend_variables(BackendParameters *param, Port *port);
557
- #else
558
- static bool save_backend_variables(BackendParameters *param, Port *port,
559
- HANDLE childProcess, pid_t childPid);
560
- #endif
561
-
562
- static void ShmemBackendArrayAdd(Backend *bn);
563
- static void ShmemBackendArrayRemove(Backend *bn);
564
- #endif /* EXEC_BACKEND */
565
-
566
- #define StartupDataBase() StartChildProcess(StartupProcess)
567
- #define StartArchiver() StartChildProcess(ArchiverProcess)
568
- #define StartBackgroundWriter() StartChildProcess(BgWriterProcess)
569
- #define StartCheckpointer() StartChildProcess(CheckpointerProcess)
570
- #define StartWalWriter() StartChildProcess(WalWriterProcess)
571
- #define StartWalReceiver() StartChildProcess(WalReceiverProcess)
572
-
573
- /* Macros to check exit status of a child process */
574
- #define EXIT_STATUS_0(st) ((st) == 0)
575
- #define EXIT_STATUS_1(st) (WIFEXITED(st) && WEXITSTATUS(st) == 1)
576
- #define EXIT_STATUS_3(st) (WIFEXITED(st) && WEXITSTATUS(st) == 3)
577
-
578
- #ifndef WIN32
579
- /*
580
- * File descriptors for pipe used to monitor if postmaster is alive.
581
- * First is POSTMASTER_FD_WATCH, second is POSTMASTER_FD_OWN.
582
- */
583
-
584
- #else
585
- /* Process handle of postmaster used for the same purpose on Windows */
586
- HANDLE PostmasterHandle;
587
- #endif
588
-
589
- /*
590
- * Postmaster main entry point
591
- */
592
- #ifdef WIN32
593
- #endif
594
- #ifdef SIGTTIN
595
- #endif
596
- #ifdef SIGTTOU
597
- #endif
598
- #ifdef SIGXFSZ
599
- #endif
600
- #ifdef HAVE_INT_OPTRESET
601
- #endif
602
- #ifdef USE_SSL
603
- #endif
604
- #ifdef WIN32
605
- #endif
606
- #ifdef EXEC_BACKEND
607
- #endif
608
- #ifdef USE_BONJOUR
609
- #endif
610
- #ifdef HAVE_PTHREAD_IS_THREADED_NP
611
- #endif
612
-
613
-
614
- /*
615
- * on_proc_exit callback to close server's listen sockets
616
- */
617
-
618
-
619
- /*
620
- * on_proc_exit callback to delete external_pid_file
621
- */
622
-
623
-
624
-
625
- /*
626
- * Compute and check the directory paths to files that are part of the
627
- * installation (as deduced from the postgres executable's own location)
628
- */
629
- #ifdef EXEC_BACKEND
630
- #endif
631
-
632
- /*
633
- * Check that pg_control exists in the correct location in the data directory.
634
- *
635
- * No attempt is made to validate the contents of pg_control here. This is
636
- * just a sanity check to see if we are looking at a real data directory.
637
- */
638
-
639
-
640
- /*
641
- * Determine how long should we let ServerLoop sleep, in milliseconds.
642
- *
643
- * In normal conditions we wait at most one minute, to ensure that the other
644
- * background tasks handled by ServerLoop get done even when no requests are
645
- * arriving. However, if there are background workers waiting to be started,
646
- * we don't actually sleep so that they are quickly serviced. Other exception
647
- * cases are as shown in the code.
648
- */
649
-
650
-
651
- /*
652
- * Activate or deactivate notifications of server socket events. Since we
653
- * don't currently have a way to remove events from an existing WaitEventSet,
654
- * we'll just destroy and recreate the whole thing. This is called during
655
- * shutdown so we can wait for backends to exit without accepting new
656
- * connections, and during crash reinitialization when we need to start
657
- * listening for new connections again. The WaitEventSet will be freed in fork
658
- * children by ClosePostmasterPorts().
659
- */
660
-
661
-
662
- /*
663
- * Main idle loop of postmaster
664
- */
665
- #ifdef HAVE_PTHREAD_IS_THREADED_NP
666
- #endif
667
-
668
- /*
669
- * Read a client's startup packet and do something according to it.
670
- *
671
- * Returns STATUS_OK or STATUS_ERROR, or might call ereport(FATAL) and
672
- * not return at all.
673
- *
674
- * (Note that ereport(FATAL) stuff is sent to the client, so only use it
675
- * if that's what you want. Return STATUS_ERROR if you don't want to
676
- * send anything to the client, which would typically be appropriate
677
- * if we detect a communications failure.)
678
- *
679
- * Set ssl_done and/or gss_done when negotiation of an encrypted layer
680
- * (currently, TLS or GSSAPI) is completed. A successful negotiation of either
681
- * encryption layer sets both flags, but a rejected negotiation sets only the
682
- * flag for that layer, since the client may wish to try the other one. We
683
- * should make no assumption here about the order in which the client may make
684
- * requests.
685
- */
686
- #ifdef USE_SSL
687
- #else
688
- #endif
689
- #ifdef USE_SSL
690
- #endif
691
- #ifdef ENABLE_GSS
692
- #endif
693
- #ifdef ENABLE_GSS
694
- #endif
695
-
696
- /*
697
- * Send a NegotiateProtocolVersion to the client. This lets the client know
698
- * that they have requested a newer minor protocol version than we are able
699
- * to speak. We'll speak the highest version we know about; the client can,
700
- * of course, abandon the connection if that's a problem.
701
- *
702
- * We also include in the response a list of protocol options we didn't
703
- * understand. This allows clients to include optional parameters that might
704
- * be present either in newer protocol versions or third-party protocol
705
- * extensions without fear of having to reconnect if those options are not
706
- * understood, while at the same time making certain that the client is aware
707
- * of which options were actually accepted.
708
- */
709
-
710
-
711
- /*
712
- * The client has sent a cancel request packet, not a normal
713
- * start-a-new-connection packet. Perform the necessary processing.
714
- * Nothing is sent back to the client.
715
- */
716
- #ifndef EXEC_BACKEND
717
- #else
718
- #endif
719
- #ifndef EXEC_BACKEND
720
- #else
721
- #endif
722
- #ifndef EXEC_BACKEND /* make GNU Emacs 26.1 see brace balance */
723
- #else
724
- #endif
725
-
726
- /*
727
- * canAcceptConnections --- check to see if database state allows connections
728
- * of the specified type. backend_type can be BACKEND_TYPE_NORMAL,
729
- * BACKEND_TYPE_AUTOVAC, or BACKEND_TYPE_BGWORKER. (Note that we don't yet
730
- * know whether a NORMAL connection might turn into a walsender.)
731
- */
732
-
733
-
734
-
735
- /*
736
- * ConnCreate -- create a local connection data structure
737
- *
738
- * Returns NULL on failure, other than out-of-memory which is fatal.
739
- */
740
-
741
-
742
-
743
- /*
744
- * ConnFree -- free a local connection data structure
745
- *
746
- * Caller has already closed the socket if any, so there's not much
747
- * to do here.
748
- */
749
-
750
-
751
-
752
- /*
753
- * ClosePostmasterPorts -- close all the postmaster's open sockets
754
- *
755
- * This is called during child process startup to release file descriptors
756
- * that are not needed by that child process. The postmaster still has
757
- * them open, of course.
758
- *
759
- * Note: we pass am_syslogger as a boolean because we don't want to set
760
- * the global variable yet when this is called.
761
- */
762
- #ifndef WIN32
763
- #endif
764
- #ifndef WIN32
765
- #else
766
- #endif
767
- #ifdef USE_BONJOUR
768
- #endif
769
-
770
-
771
- /*
772
- * InitProcessGlobals -- set MyProcPid, MyStartTime[stamp], random seeds
773
- *
774
- * Called early in the postmaster and every backend.
775
- */
776
- #ifndef WIN32
777
- #endif
778
-
779
- /*
780
- * Child processes use SIGUSR1 to notify us of 'pmsignals'. pg_ctl uses
781
- * SIGUSR1 to ask postmaster to check for logrotate and promote files.
782
- */
783
-
784
-
785
- /*
786
- * pg_ctl uses SIGHUP to request a reload of the configuration files.
787
- */
788
-
789
-
790
- /*
791
- * Re-read config files, and tell children to do same.
792
- */
793
- #ifdef USE_SSL
794
- #endif
795
- #ifdef EXEC_BACKEND
796
- #endif
797
-
798
- /*
799
- * pg_ctl uses SIGTERM, SIGINT and SIGQUIT to request different types of
800
- * shutdown.
801
- */
802
-
803
-
804
- /*
805
- * Process shutdown request.
806
- */
807
- #ifdef USE_SYSTEMD
808
- #endif
809
- #ifdef USE_SYSTEMD
810
- #endif
811
- #ifdef USE_SYSTEMD
812
- #endif
813
-
814
-
815
-
816
- /*
817
- * Cleanup after a child process dies.
818
- */
819
- #ifdef USE_SYSTEMD
820
- #endif
821
-
822
- /*
823
- * Scan the bgworkers list and see if the given PID (which has just stopped
824
- * or crashed) is in it. Handle its shutdown if so, and return true. If not a
825
- * bgworker, return false.
826
- *
827
- * This is heavily based on CleanupBackend. One important difference is that
828
- * we don't know yet that the dying process is a bgworker, so we must be silent
829
- * until we're sure it is.
830
- */
831
- #ifdef WIN32
832
- #endif
833
- #ifdef EXEC_BACKEND
834
- #endif
835
-
836
- /*
837
- * CleanupBackend -- cleanup after terminated backend.
838
- *
839
- * Remove all local state associated with backend.
840
- *
841
- * If you change this, see also CleanupBackgroundWorker.
842
- */
843
- #ifdef WIN32
844
- #endif
845
- #ifdef EXEC_BACKEND
846
- #endif
847
-
848
- /*
849
- * HandleChildCrash -- cleanup after failed backend, bgwriter, checkpointer,
850
- * walwriter, autovacuum, archiver or background worker.
851
- *
852
- * The objectives here are to clean up our local state about the child
853
- * process, and to signal all other remaining children to quickdie.
854
- */
855
- #ifdef EXEC_BACKEND
856
- #endif
857
- #ifdef EXEC_BACKEND
858
- #endif
859
-
860
- /*
861
- * Log the death of a child process.
862
- */
863
- #if defined(WIN32)
864
- #else
865
- #endif
866
-
867
- /*
868
- * Advance the postmaster's state machine and take actions as appropriate
869
- *
870
- * This is common code for process_pm_shutdown_request(),
871
- * process_pm_child_exit() and process_pm_pmsignal(), which process the signals
872
- * that might mean we need to change state.
873
- */
874
-
875
-
876
-
877
- /*
878
- * Send a signal to a postmaster child process
879
- *
880
- * On systems that have setsid(), each child process sets itself up as a
881
- * process group leader. For signals that are generally interpreted in the
882
- * appropriate fashion, we signal the entire process group not just the
883
- * direct child process. This allows us to, for example, SIGQUIT a blocked
884
- * archive_recovery script, or SIGINT a script being run by a backend via
885
- * system().
886
- *
887
- * There is a race condition for recently-forked children: they might not
888
- * have executed setsid() yet. So we signal the child directly as well as
889
- * the group. We assume such a child will handle the signal before trying
890
- * to spawn any grandchild processes. We also assume that signaling the
891
- * child twice will not cause any problems.
892
- */
893
- #ifdef HAVE_SETSID
894
- #endif
895
-
896
- /*
897
- * Convenience function for killing a child process after a crash of some
898
- * other child process. We log the action at a higher level than we would
899
- * otherwise do, and we apply send_abort_for_crash to decide which signal
900
- * to send. Normally it's SIGQUIT -- and most other comments in this file
901
- * are written on the assumption that it is -- but developers might prefer
902
- * to use SIGABRT to collect per-child core dumps.
903
- */
904
-
905
-
906
- /*
907
- * Send a signal to the targeted children (but NOT special children;
908
- * dead_end children are never signaled, either).
909
- */
910
-
911
-
912
- /*
913
- * Send a termination signal to children. This considers all of our children
914
- * processes, except syslogger and dead_end backends.
915
- */
916
-
917
-
918
- /*
919
- * BackendStartup -- start backend process
920
- *
921
- * returns: STATUS_ERROR if the fork failed, STATUS_OK otherwise.
922
- *
923
- * Note: if you change this code, also consider StartAutovacuumWorker.
924
- */
925
- #ifdef EXEC_BACKEND
926
- #else /* !EXEC_BACKEND */
927
- #endif /* EXEC_BACKEND */
928
- #ifdef EXEC_BACKEND
929
- #endif
930
-
931
- /*
932
- * Try to report backend fork() failure to client before we close the
933
- * connection. Since we do not care to risk blocking the postmaster on
934
- * this connection, we set the connection to non-blocking and try only once.
935
- *
936
- * This is grungy special-purpose code; we cannot use backend libpq since
937
- * it's not up and running.
938
- */
939
-
940
-
941
-
942
- /*
943
- * BackendInitialize -- initialize an interactive (postmaster-child)
944
- * backend process, and collect the client's startup packet.
945
- *
946
- * returns: nothing. Will not return at all if there's any failure.
947
- *
948
- * Note: this code does not depend on having any access to shared memory.
949
- * Indeed, our approach to SIGTERM/timeout handling *requires* that
950
- * shared memory not have been touched yet; see comments within.
951
- * In the EXEC_BACKEND case, we are physically attached to shared memory
952
- * but have not yet set up most of our local pointers to shmem structures.
953
- */
954
-
955
-
956
-
957
- /*
958
- * BackendRun -- set up the backend's argument list and invoke PostgresMain()
959
- *
960
- * returns:
961
- * Doesn't return at all.
962
- */
963
-
964
-
965
-
966
- #ifdef EXEC_BACKEND
967
-
968
- /*
969
- * postmaster_forkexec -- fork and exec a postmaster subprocess
970
- *
971
- * The caller must have set up the argv array already, except for argv[2]
972
- * which will be filled with the name of the temp variable file.
973
- *
974
- * Returns the child process PID, or -1 on fork failure (a suitable error
975
- * message has been logged on failure).
976
- *
977
- * All uses of this routine will dispatch to SubPostmasterMain in the
978
- * child process.
979
- */
980
- pid_t
981
- postmaster_forkexec(int argc, char *argv[])
982
- {
983
- Port port;
984
-
985
- /* This entry point passes dummy values for the Port variables */
986
- memset(&port, 0, sizeof(port));
987
- return internal_forkexec(argc, argv, &port);
988
- }
989
-
990
- /*
991
- * backend_forkexec -- fork/exec off a backend process
992
- *
993
- * Some operating systems (WIN32) don't have fork() so we have to simulate
994
- * it by storing parameters that need to be passed to the child and
995
- * then create a new child process.
996
- *
997
- * returns the pid of the fork/exec'd process, or -1 on failure
998
- */
999
- static pid_t
1000
- backend_forkexec(Port *port)
1001
- {
1002
- char *av[4];
1003
- int ac = 0;
1004
-
1005
- av[ac++] = "postgres";
1006
- av[ac++] = "--forkbackend";
1007
- av[ac++] = NULL; /* filled in by internal_forkexec */
1008
-
1009
- av[ac] = NULL;
1010
- Assert(ac < lengthof(av));
1011
-
1012
- return internal_forkexec(ac, av, port);
1013
- }
1014
-
1015
- #ifndef WIN32
1016
-
1017
- /*
1018
- * internal_forkexec non-win32 implementation
1019
- *
1020
- * - writes out backend variables to the parameter file
1021
- * - fork():s, and then exec():s the child process
1022
- */
1023
- static pid_t
1024
- internal_forkexec(int argc, char *argv[], Port *port)
1025
- {
1026
- static unsigned long tmpBackendFileNum = 0;
1027
- pid_t pid;
1028
- char tmpfilename[MAXPGPATH];
1029
- BackendParameters param;
1030
- FILE *fp;
1031
-
1032
- if (!save_backend_variables(&param, port))
1033
- return -1; /* log made by save_backend_variables */
1034
-
1035
- /* Calculate name for temp file */
1036
- snprintf(tmpfilename, MAXPGPATH, "%s/%s.backend_var.%d.%lu",
1037
- PG_TEMP_FILES_DIR, PG_TEMP_FILE_PREFIX,
1038
- MyProcPid, ++tmpBackendFileNum);
1039
-
1040
- /* Open file */
1041
- fp = AllocateFile(tmpfilename, PG_BINARY_W);
1042
- if (!fp)
1043
- {
1044
- /*
1045
- * As in OpenTemporaryFileInTablespace, try to make the temp-file
1046
- * directory, ignoring errors.
1047
- */
1048
- (void) MakePGDirectory(PG_TEMP_FILES_DIR);
1049
-
1050
- fp = AllocateFile(tmpfilename, PG_BINARY_W);
1051
- if (!fp)
1052
- {
1053
- ereport(LOG,
1054
- (errcode_for_file_access(),
1055
- errmsg("could not create file \"%s\": %m",
1056
- tmpfilename)));
1057
- return -1;
1058
- }
1059
- }
1060
-
1061
- if (fwrite(&param, sizeof(param), 1, fp) != 1)
1062
- {
1063
- ereport(LOG,
1064
- (errcode_for_file_access(),
1065
- errmsg("could not write to file \"%s\": %m", tmpfilename)));
1066
- FreeFile(fp);
1067
- return -1;
1068
- }
1069
-
1070
- /* Release file */
1071
- if (FreeFile(fp))
1072
- {
1073
- ereport(LOG,
1074
- (errcode_for_file_access(),
1075
- errmsg("could not write to file \"%s\": %m", tmpfilename)));
1076
- return -1;
1077
- }
1078
-
1079
- /* Make sure caller set up argv properly */
1080
- Assert(argc >= 3);
1081
- Assert(argv[argc] == NULL);
1082
- Assert(strncmp(argv[1], "--fork", 6) == 0);
1083
- Assert(argv[2] == NULL);
1084
-
1085
- /* Insert temp file name after --fork argument */
1086
- argv[2] = tmpfilename;
1087
-
1088
- /* Fire off execv in child */
1089
- if ((pid = fork_process()) == 0)
1090
- {
1091
- if (execv(postgres_exec_path, argv) < 0)
1092
- {
1093
- ereport(LOG,
1094
- (errmsg("could not execute server process \"%s\": %m",
1095
- postgres_exec_path)));
1096
- /* We're already in the child process here, can't return */
1097
- exit(1);
1098
- }
1099
- }
1100
-
1101
- return pid; /* Parent returns pid, or -1 on fork failure */
1102
- }
1103
- #else /* WIN32 */
1104
-
1105
- /*
1106
- * internal_forkexec win32 implementation
1107
- *
1108
- * - starts backend using CreateProcess(), in suspended state
1109
- * - writes out backend variables to the parameter file
1110
- * - during this, duplicates handles and sockets required for
1111
- * inheritance into the new process
1112
- * - resumes execution of the new process once the backend parameter
1113
- * file is complete.
1114
- */
1115
- static pid_t
1116
- internal_forkexec(int argc, char *argv[], Port *port)
1117
- {
1118
- int retry_count = 0;
1119
- STARTUPINFO si;
1120
- PROCESS_INFORMATION pi;
1121
- int i;
1122
- int j;
1123
- char cmdLine[MAXPGPATH * 2];
1124
- HANDLE paramHandle;
1125
- BackendParameters *param;
1126
- SECURITY_ATTRIBUTES sa;
1127
- char paramHandleStr[32];
1128
- win32_deadchild_waitinfo *childinfo;
1129
-
1130
- /* Make sure caller set up argv properly */
1131
- Assert(argc >= 3);
1132
- Assert(argv[argc] == NULL);
1133
- Assert(strncmp(argv[1], "--fork", 6) == 0);
1134
- Assert(argv[2] == NULL);
1135
-
1136
- /* Resume here if we need to retry */
1137
- retry:
1138
-
1139
- /* Set up shared memory for parameter passing */
1140
- ZeroMemory(&sa, sizeof(sa));
1141
- sa.nLength = sizeof(sa);
1142
- sa.bInheritHandle = TRUE;
1143
- paramHandle = CreateFileMapping(INVALID_HANDLE_VALUE,
1144
- &sa,
1145
- PAGE_READWRITE,
1146
- 0,
1147
- sizeof(BackendParameters),
1148
- NULL);
1149
- if (paramHandle == INVALID_HANDLE_VALUE)
1150
- {
1151
- ereport(LOG,
1152
- (errmsg("could not create backend parameter file mapping: error code %lu",
1153
- GetLastError())));
1154
- return -1;
1155
- }
1156
-
1157
- param = MapViewOfFile(paramHandle, FILE_MAP_WRITE, 0, 0, sizeof(BackendParameters));
1158
- if (!param)
1159
- {
1160
- ereport(LOG,
1161
- (errmsg("could not map backend parameter memory: error code %lu",
1162
- GetLastError())));
1163
- CloseHandle(paramHandle);
1164
- return -1;
1165
- }
1166
-
1167
- /* Insert temp file name after --fork argument */
1168
- #ifdef _WIN64
1169
- sprintf(paramHandleStr, "%llu", (LONG_PTR) paramHandle);
1170
- #else
1171
- sprintf(paramHandleStr, "%lu", (DWORD) paramHandle);
1172
- #endif
1173
- argv[2] = paramHandleStr;
1174
-
1175
- /* Format the cmd line */
1176
- cmdLine[sizeof(cmdLine) - 1] = '\0';
1177
- cmdLine[sizeof(cmdLine) - 2] = '\0';
1178
- snprintf(cmdLine, sizeof(cmdLine) - 1, "\"%s\"", postgres_exec_path);
1179
- i = 0;
1180
- while (argv[++i] != NULL)
1181
- {
1182
- j = strlen(cmdLine);
1183
- snprintf(cmdLine + j, sizeof(cmdLine) - 1 - j, " \"%s\"", argv[i]);
1184
- }
1185
- if (cmdLine[sizeof(cmdLine) - 2] != '\0')
1186
- {
1187
- ereport(LOG,
1188
- (errmsg("subprocess command line too long")));
1189
- UnmapViewOfFile(param);
1190
- CloseHandle(paramHandle);
1191
- return -1;
1192
- }
1193
-
1194
- memset(&pi, 0, sizeof(pi));
1195
- memset(&si, 0, sizeof(si));
1196
- si.cb = sizeof(si);
1197
-
1198
- /*
1199
- * Create the subprocess in a suspended state. This will be resumed later,
1200
- * once we have written out the parameter file.
1201
- */
1202
- if (!CreateProcess(NULL, cmdLine, NULL, NULL, TRUE, CREATE_SUSPENDED,
1203
- NULL, NULL, &si, &pi))
1204
- {
1205
- ereport(LOG,
1206
- (errmsg("CreateProcess() call failed: %m (error code %lu)",
1207
- GetLastError())));
1208
- UnmapViewOfFile(param);
1209
- CloseHandle(paramHandle);
1210
- return -1;
1211
- }
1212
-
1213
- if (!save_backend_variables(param, port, pi.hProcess, pi.dwProcessId))
1214
- {
1215
- /*
1216
- * log made by save_backend_variables, but we have to clean up the
1217
- * mess with the half-started process
1218
- */
1219
- if (!TerminateProcess(pi.hProcess, 255))
1220
- ereport(LOG,
1221
- (errmsg_internal("could not terminate unstarted process: error code %lu",
1222
- GetLastError())));
1223
- CloseHandle(pi.hProcess);
1224
- CloseHandle(pi.hThread);
1225
- UnmapViewOfFile(param);
1226
- CloseHandle(paramHandle);
1227
- return -1; /* log made by save_backend_variables */
1228
- }
1229
-
1230
- /* Drop the parameter shared memory that is now inherited to the backend */
1231
- if (!UnmapViewOfFile(param))
1232
- ereport(LOG,
1233
- (errmsg("could not unmap view of backend parameter file: error code %lu",
1234
- GetLastError())));
1235
- if (!CloseHandle(paramHandle))
1236
- ereport(LOG,
1237
- (errmsg("could not close handle to backend parameter file: error code %lu",
1238
- GetLastError())));
1239
-
1240
- /*
1241
- * Reserve the memory region used by our main shared memory segment before
1242
- * we resume the child process. Normally this should succeed, but if ASLR
1243
- * is active then it might sometimes fail due to the stack or heap having
1244
- * gotten mapped into that range. In that case, just terminate the
1245
- * process and retry.
1246
- */
1247
- if (!pgwin32_ReserveSharedMemoryRegion(pi.hProcess))
1248
- {
1249
- /* pgwin32_ReserveSharedMemoryRegion already made a log entry */
1250
- if (!TerminateProcess(pi.hProcess, 255))
1251
- ereport(LOG,
1252
- (errmsg_internal("could not terminate process that failed to reserve memory: error code %lu",
1253
- GetLastError())));
1254
- CloseHandle(pi.hProcess);
1255
- CloseHandle(pi.hThread);
1256
- if (++retry_count < 100)
1257
- goto retry;
1258
- ereport(LOG,
1259
- (errmsg("giving up after too many tries to reserve shared memory"),
1260
- errhint("This might be caused by ASLR or antivirus software.")));
1261
- return -1;
1262
- }
1263
-
1264
- /*
1265
- * Now that the backend variables are written out, we start the child
1266
- * thread so it can start initializing while we set up the rest of the
1267
- * parent state.
1268
- */
1269
- if (ResumeThread(pi.hThread) == -1)
1270
- {
1271
- if (!TerminateProcess(pi.hProcess, 255))
1272
- {
1273
- ereport(LOG,
1274
- (errmsg_internal("could not terminate unstartable process: error code %lu",
1275
- GetLastError())));
1276
- CloseHandle(pi.hProcess);
1277
- CloseHandle(pi.hThread);
1278
- return -1;
1279
- }
1280
- CloseHandle(pi.hProcess);
1281
- CloseHandle(pi.hThread);
1282
- ereport(LOG,
1283
- (errmsg_internal("could not resume thread of unstarted process: error code %lu",
1284
- GetLastError())));
1285
- return -1;
1286
- }
1287
-
1288
- /*
1289
- * Queue a waiter to signal when this child dies. The wait will be handled
1290
- * automatically by an operating system thread pool. The memory will be
1291
- * freed by a later call to waitpid().
1292
- */
1293
- childinfo = palloc(sizeof(win32_deadchild_waitinfo));
1294
- childinfo->procHandle = pi.hProcess;
1295
- childinfo->procId = pi.dwProcessId;
1296
-
1297
- if (!RegisterWaitForSingleObject(&childinfo->waitHandle,
1298
- pi.hProcess,
1299
- pgwin32_deadchild_callback,
1300
- childinfo,
1301
- INFINITE,
1302
- WT_EXECUTEONLYONCE | WT_EXECUTEINWAITTHREAD))
1303
- ereport(FATAL,
1304
- (errmsg_internal("could not register process for wait: error code %lu",
1305
- GetLastError())));
1306
-
1307
- /* Don't close pi.hProcess here - waitpid() needs access to it */
1308
-
1309
- CloseHandle(pi.hThread);
1310
-
1311
- return pi.dwProcessId;
1312
- }
1313
- #endif /* WIN32 */
1314
-
1315
-
1316
- /*
1317
- * SubPostmasterMain -- Get the fork/exec'd process into a state equivalent
1318
- * to what it would be if we'd simply forked on Unix, and then
1319
- * dispatch to the appropriate place.
1320
- *
1321
- * The first two command line arguments are expected to be "--forkFOO"
1322
- * (where FOO indicates which postmaster child we are to become), and
1323
- * the name of a variables file that we can read to load data that would
1324
- * have been inherited by fork() on Unix. Remaining arguments go to the
1325
- * subprocess FooMain() routine.
1326
- */
1327
- void
1328
- SubPostmasterMain(int argc, char *argv[])
1329
- {
1330
- Port port;
1331
-
1332
- /* In EXEC_BACKEND case we will not have inherited these settings */
1333
- IsPostmasterEnvironment = true;
1334
- whereToSendOutput = DestNone;
1335
-
1336
- /* Setup essential subsystems (to ensure elog() behaves sanely) */
1337
- InitializeGUCOptions();
1338
-
1339
- /* Check we got appropriate args */
1340
- if (argc < 3)
1341
- elog(FATAL, "invalid subpostmaster invocation");
1342
-
1343
- /* Read in the variables file */
1344
- memset(&port, 0, sizeof(Port));
1345
- read_backend_variables(argv[2], &port);
1346
-
1347
- /* Close the postmaster's sockets (as soon as we know them) */
1348
- ClosePostmasterPorts(strcmp(argv[1], "--forklog") == 0);
1349
-
1350
- /* Setup as postmaster child */
1351
- InitPostmasterChild();
1352
-
1353
- /*
1354
- * If appropriate, physically re-attach to shared memory segment. We want
1355
- * to do this before going any further to ensure that we can attach at the
1356
- * same address the postmaster used. On the other hand, if we choose not
1357
- * to re-attach, we may have other cleanup to do.
1358
- *
1359
- * If testing EXEC_BACKEND on Linux, you should run this as root before
1360
- * starting the postmaster:
1361
- *
1362
- * sysctl -w kernel.randomize_va_space=0
1363
- *
1364
- * This prevents using randomized stack and code addresses that cause the
1365
- * child process's memory map to be different from the parent's, making it
1366
- * sometimes impossible to attach to shared memory at the desired address.
1367
- * Return the setting to its old value (usually '1' or '2') when finished.
1368
- */
1369
- if (strcmp(argv[1], "--forkbackend") == 0 ||
1370
- strcmp(argv[1], "--forkavlauncher") == 0 ||
1371
- strcmp(argv[1], "--forkavworker") == 0 ||
1372
- strcmp(argv[1], "--forkaux") == 0 ||
1373
- strncmp(argv[1], "--forkbgworker=", 15) == 0)
1374
- PGSharedMemoryReAttach();
1375
- else
1376
- PGSharedMemoryNoReAttach();
1377
-
1378
- /* autovacuum needs this set before calling InitProcess */
1379
- if (strcmp(argv[1], "--forkavlauncher") == 0)
1380
- AutovacuumLauncherIAm();
1381
- if (strcmp(argv[1], "--forkavworker") == 0)
1382
- AutovacuumWorkerIAm();
1383
-
1384
- /* Read in remaining GUC variables */
1385
- read_nondefault_variables();
1386
-
1387
- /*
1388
- * Check that the data directory looks valid, which will also check the
1389
- * privileges on the data directory and update our umask and file/group
1390
- * variables for creating files later. Note: this should really be done
1391
- * before we create any files or directories.
1392
- */
1393
- checkDataDir();
1394
-
1395
- /*
1396
- * (re-)read control file, as it contains config. The postmaster will
1397
- * already have read this, but this process doesn't know about that.
1398
- */
1399
- LocalProcessControlFile(false);
1400
-
1401
- /*
1402
- * Reload any libraries that were preloaded by the postmaster. Since we
1403
- * exec'd this process, those libraries didn't come along with us; but we
1404
- * should load them into all child processes to be consistent with the
1405
- * non-EXEC_BACKEND behavior.
1406
- */
1407
- process_shared_preload_libraries();
1408
-
1409
- /* Run backend or appropriate child */
1410
- if (strcmp(argv[1], "--forkbackend") == 0)
1411
- {
1412
- Assert(argc == 3); /* shouldn't be any more args */
1413
-
1414
- /*
1415
- * Need to reinitialize the SSL library in the backend, since the
1416
- * context structures contain function pointers and cannot be passed
1417
- * through the parameter file.
1418
- *
1419
- * If for some reason reload fails (maybe the user installed broken
1420
- * key files), soldier on without SSL; that's better than all
1421
- * connections becoming impossible.
1422
- *
1423
- * XXX should we do this in all child processes? For the moment it's
1424
- * enough to do it in backend children.
1425
- */
1426
- #ifdef USE_SSL
1427
- if (EnableSSL)
1428
- {
1429
- if (secure_initialize(false) == 0)
1430
- LoadedSSL = true;
1431
- else
1432
- ereport(LOG,
1433
- (errmsg("SSL configuration could not be loaded in child process")));
1434
- }
1435
- #endif
1436
-
1437
- /*
1438
- * Perform additional initialization and collect startup packet.
1439
- *
1440
- * We want to do this before InitProcess() for a couple of reasons: 1.
1441
- * so that we aren't eating up a PGPROC slot while waiting on the
1442
- * client. 2. so that if InitProcess() fails due to being out of
1443
- * PGPROC slots, we have already initialized libpq and are able to
1444
- * report the error to the client.
1445
- */
1446
- BackendInitialize(&port);
1447
-
1448
- /* Restore basic shared memory pointers */
1449
- InitShmemAccess(UsedShmemSegAddr);
1450
-
1451
- /* Need a PGPROC to run CreateSharedMemoryAndSemaphores */
1452
- InitProcess();
1453
-
1454
- /* Attach process to shared data structures */
1455
- CreateSharedMemoryAndSemaphores();
1456
-
1457
- /* And run the backend */
1458
- BackendRun(&port); /* does not return */
1459
- }
1460
- if (strcmp(argv[1], "--forkaux") == 0)
1461
- {
1462
- AuxProcType auxtype;
1463
-
1464
- Assert(argc == 4);
1465
-
1466
- /* Restore basic shared memory pointers */
1467
- InitShmemAccess(UsedShmemSegAddr);
1468
-
1469
- /* Need a PGPROC to run CreateSharedMemoryAndSemaphores */
1470
- InitAuxiliaryProcess();
1471
-
1472
- /* Attach process to shared data structures */
1473
- CreateSharedMemoryAndSemaphores();
1474
-
1475
- auxtype = atoi(argv[3]);
1476
- AuxiliaryProcessMain(auxtype); /* does not return */
1477
- }
1478
- if (strcmp(argv[1], "--forkavlauncher") == 0)
1479
- {
1480
- /* Restore basic shared memory pointers */
1481
- InitShmemAccess(UsedShmemSegAddr);
1482
-
1483
- /* Need a PGPROC to run CreateSharedMemoryAndSemaphores */
1484
- InitProcess();
1485
-
1486
- /* Attach process to shared data structures */
1487
- CreateSharedMemoryAndSemaphores();
1488
-
1489
- AutoVacLauncherMain(argc - 2, argv + 2); /* does not return */
1490
- }
1491
- if (strcmp(argv[1], "--forkavworker") == 0)
1492
- {
1493
- /* Restore basic shared memory pointers */
1494
- InitShmemAccess(UsedShmemSegAddr);
1495
-
1496
- /* Need a PGPROC to run CreateSharedMemoryAndSemaphores */
1497
- InitProcess();
1498
-
1499
- /* Attach process to shared data structures */
1500
- CreateSharedMemoryAndSemaphores();
1501
-
1502
- AutoVacWorkerMain(argc - 2, argv + 2); /* does not return */
1503
- }
1504
- if (strncmp(argv[1], "--forkbgworker=", 15) == 0)
1505
- {
1506
- int shmem_slot;
1507
-
1508
- /* do this as early as possible; in particular, before InitProcess() */
1509
- IsBackgroundWorker = true;
1510
-
1511
- /* Restore basic shared memory pointers */
1512
- InitShmemAccess(UsedShmemSegAddr);
1513
-
1514
- /* Need a PGPROC to run CreateSharedMemoryAndSemaphores */
1515
- InitProcess();
1516
-
1517
- /* Attach process to shared data structures */
1518
- CreateSharedMemoryAndSemaphores();
1519
-
1520
- /* Fetch MyBgworkerEntry from shared memory */
1521
- shmem_slot = atoi(argv[1] + 15);
1522
- MyBgworkerEntry = BackgroundWorkerEntry(shmem_slot);
1523
-
1524
- StartBackgroundWorker();
1525
- }
1526
- if (strcmp(argv[1], "--forklog") == 0)
1527
- {
1528
- /* Do not want to attach to shared memory */
1529
-
1530
- SysLoggerMain(argc, argv); /* does not return */
1531
- }
1532
-
1533
- abort(); /* shouldn't get here */
1534
- }
1535
- #endif /* EXEC_BACKEND */
1536
-
1537
-
1538
- /*
1539
- * ExitPostmaster -- cleanup
1540
- *
1541
- * Do NOT call exit() directly --- always go through here!
1542
- */
1543
- #ifdef HAVE_PTHREAD_IS_THREADED_NP
1544
- #endif
1545
-
1546
- /*
1547
- * Handle pmsignal conditions representing requests from backends,
1548
- * and check for promote and logrotate requests from pg_ctl.
1549
- */
1550
- #ifdef USE_SYSTEMD
1551
- #endif
1552
- #ifdef USE_SYSTEMD
1553
- #endif
1554
-
1555
- /*
1556
- * SIGTERM while processing startup packet.
1557
- *
1558
- * Running proc_exit() from a signal handler would be quite unsafe.
1559
- * However, since we have not yet touched shared memory, we can just
1560
- * pull the plug and exit without running any atexit handlers.
1561
- *
1562
- * One might be tempted to try to send a message, or log one, indicating
1563
- * why we are disconnecting. However, that would be quite unsafe in itself.
1564
- * Also, it seems undesirable to provide clues about the database's state
1565
- * to a client that has not yet completed authentication, or even sent us
1566
- * a startup packet.
1567
- */
1568
-
1569
-
1570
- /*
1571
- * Dummy signal handler
1572
- *
1573
- * We use this for signals that we don't actually use in the postmaster,
1574
- * but we do use in backends. If we were to SIG_IGN such signals in the
1575
- * postmaster, then a newly started backend might drop a signal that arrives
1576
- * before it's able to reconfigure its signal processing. (See notes in
1577
- * tcop/postgres.c.)
1578
- */
1579
-
1580
-
1581
- /*
1582
- * Timeout while processing startup packet.
1583
- * As for process_startup_packet_die(), we exit via _exit(1).
1584
- */
1585
-
1586
-
1587
-
1588
- /*
1589
- * Generate a random cancel key.
1590
- */
1591
-
1592
-
1593
- /*
1594
- * Count up number of child processes of specified types (dead_end children
1595
- * are always excluded).
1596
- */
1597
-
1598
-
1599
-
1600
- /*
1601
- * StartChildProcess -- start an auxiliary process for the postmaster
1602
- *
1603
- * "type" determines what kind of child will be started. All child types
1604
- * initially go to AuxiliaryProcessMain, which will handle common setup.
1605
- *
1606
- * Return value of StartChildProcess is subprocess' PID, or 0 if failed
1607
- * to start subprocess.
1608
- */
1609
- #ifdef EXEC_BACKEND
1610
- #else /* !EXEC_BACKEND */
1611
- #endif /* EXEC_BACKEND */
1612
-
1613
- /*
1614
- * StartAutovacuumWorker
1615
- * Start an autovac worker process.
1616
- *
1617
- * This function is here because it enters the resulting PID into the
1618
- * postmaster's private backends list.
1619
- *
1620
- * NB -- this code very roughly matches BackendStartup.
1621
- */
1622
- #ifdef EXEC_BACKEND
1623
- #endif
1624
-
1625
- /*
1626
- * MaybeStartWalReceiver
1627
- * Start the WAL receiver process, if not running and our state allows.
1628
- *
1629
- * Note: if WalReceiverPID is already nonzero, it might seem that we should
1630
- * clear WalReceiverRequested. However, there's a race condition if the
1631
- * walreceiver terminates and the startup process immediately requests a new
1632
- * one: it's quite possible to get the signal for the request before reaping
1633
- * the dead walreceiver process. Better to risk launching an extra
1634
- * walreceiver than to miss launching one we need. (The walreceiver code
1635
- * has logic to recognize that it should go away if not needed.)
1636
- */
1637
-
1638
-
1639
-
1640
- /*
1641
- * Create the opts file
1642
- */
1643
- #define OPTS_FILE "postmaster.opts"
1644
-
1645
-
1646
- /*
1647
- * MaxLivePostmasterChildren
1648
- *
1649
- * This reports the number of entries needed in per-child-process arrays
1650
- * (the PMChildFlags array, and if EXEC_BACKEND the ShmemBackendArray).
1651
- * These arrays include regular backends, autovac workers, walsenders
1652
- * and background workers, but not special children nor dead_end children.
1653
- * This allows the arrays to have a fixed maximum size, to wit the same
1654
- * too-many-children limit enforced by canAcceptConnections(). The exact value
1655
- * isn't too critical as long as it's more than MaxBackends.
1656
- */
1657
-
1658
-
1659
- /*
1660
- * Connect background worker to a database.
1661
- */
1662
-
1663
-
1664
- /*
1665
- * Connect background worker to a database using OIDs.
1666
- */
1667
-
1668
-
1669
- /*
1670
- * Block/unblock signals in a background worker
1671
- */
1672
-
1673
-
1674
-
1675
-
1676
- #ifdef EXEC_BACKEND
1677
- static pid_t
1678
- bgworker_forkexec(int shmem_slot)
1679
- {
1680
- char *av[10];
1681
- int ac = 0;
1682
- char forkav[MAXPGPATH];
1683
-
1684
- snprintf(forkav, MAXPGPATH, "--forkbgworker=%d", shmem_slot);
1685
-
1686
- av[ac++] = "postgres";
1687
- av[ac++] = forkav;
1688
- av[ac++] = NULL; /* filled in by postmaster_forkexec */
1689
- av[ac] = NULL;
1690
-
1691
- Assert(ac < lengthof(av));
1692
-
1693
- return postmaster_forkexec(ac, av);
1694
- }
1695
- #endif
1696
-
1697
- /*
1698
- * Start a new bgworker.
1699
- * Starting time conditions must have been checked already.
1700
- *
1701
- * Returns true on success, false on failure.
1702
- * In either case, update the RegisteredBgWorker's state appropriately.
1703
- *
1704
- * This code is heavily based on autovacuum.c, q.v.
1705
- */
1706
- #ifdef EXEC_BACKEND
1707
- #else
1708
- #endif
1709
- #ifndef EXEC_BACKEND
1710
- #endif
1711
- #ifdef EXEC_BACKEND
1712
- #endif
1713
-
1714
- /*
1715
- * Does the current postmaster state require starting a worker with the
1716
- * specified start_time?
1717
- */
1718
-
1719
-
1720
- /*
1721
- * Allocate the Backend struct for a connected background worker, but don't
1722
- * add it to the list of backends just yet.
1723
- *
1724
- * On failure, return false without changing any worker state.
1725
- *
1726
- * Some info from the Backend is copied into the passed rw.
1727
- */
1728
-
1729
-
1730
- /*
1731
- * If the time is right, start background worker(s).
1732
- *
1733
- * As a side effect, the bgworker control variables are set or reset
1734
- * depending on whether more workers may need to be started.
1735
- *
1736
- * We limit the number of workers started per call, to avoid consuming the
1737
- * postmaster's attention for too long when many such requests are pending.
1738
- * As long as StartWorkerNeeded is true, ServerLoop will not block and will
1739
- * call this function again after dealing with any other issues.
1740
- */
1741
- #define MAX_BGWORKERS_TO_LAUNCH 100
1742
-
1743
- /*
1744
- * When a backend asks to be notified about worker state changes, we
1745
- * set a flag in its backend entry. The background worker machinery needs
1746
- * to know when such backends exit.
1747
- */
1748
-
1749
-
1750
- #ifdef EXEC_BACKEND
1751
-
1752
- /*
1753
- * The following need to be available to the save/restore_backend_variables
1754
- * functions. They are marked NON_EXEC_STATIC in their home modules.
1755
- */
1756
- extern slock_t *ShmemLock;
1757
- extern slock_t *ProcStructLock;
1758
- extern PGPROC *AuxiliaryProcs;
1759
- extern PMSignalData *PMSignalState;
1760
- extern pg_time_t first_syslogger_file_time;
1761
-
1762
- #ifndef WIN32
1763
- #define write_inheritable_socket(dest, src, childpid) ((*(dest) = (src)), true)
1764
- #define read_inheritable_socket(dest, src) (*(dest) = *(src))
1765
- #else
1766
- static bool write_duplicated_handle(HANDLE *dest, HANDLE src, HANDLE child);
1767
- static bool write_inheritable_socket(InheritableSocket *dest, SOCKET src,
1768
- pid_t childPid);
1769
- static void read_inheritable_socket(SOCKET *dest, InheritableSocket *src);
1770
- #endif
1771
-
1772
-
1773
- /* Save critical backend variables into the BackendParameters struct */
1774
- #ifndef WIN32
1775
- static bool
1776
- save_backend_variables(BackendParameters *param, Port *port)
1777
- #else
1778
- static bool
1779
- save_backend_variables(BackendParameters *param, Port *port,
1780
- HANDLE childProcess, pid_t childPid)
1781
- #endif
1782
- {
1783
- memcpy(&param->port, port, sizeof(Port));
1784
- if (!write_inheritable_socket(&param->portsocket, port->sock, childPid))
1785
- return false;
1786
-
1787
- strlcpy(param->DataDir, DataDir, MAXPGPATH);
1788
-
1789
- memcpy(&param->ListenSocket, &ListenSocket, sizeof(ListenSocket));
1790
-
1791
- param->MyCancelKey = MyCancelKey;
1792
- param->MyPMChildSlot = MyPMChildSlot;
1793
-
1794
- #ifdef WIN32
1795
- param->ShmemProtectiveRegion = ShmemProtectiveRegion;
1796
- #endif
1797
- param->UsedShmemSegID = UsedShmemSegID;
1798
- param->UsedShmemSegAddr = UsedShmemSegAddr;
1799
-
1800
- param->ShmemLock = ShmemLock;
1801
- param->ShmemVariableCache = ShmemVariableCache;
1802
- param->ShmemBackendArray = ShmemBackendArray;
1803
-
1804
- #ifndef HAVE_SPINLOCKS
1805
- param->SpinlockSemaArray = SpinlockSemaArray;
1806
- #endif
1807
- param->NamedLWLockTrancheRequests = NamedLWLockTrancheRequests;
1808
- param->NamedLWLockTrancheArray = NamedLWLockTrancheArray;
1809
- param->MainLWLockArray = MainLWLockArray;
1810
- param->ProcStructLock = ProcStructLock;
1811
- param->ProcGlobal = ProcGlobal;
1812
- param->AuxiliaryProcs = AuxiliaryProcs;
1813
- param->PreparedXactProcs = PreparedXactProcs;
1814
- param->PMSignalState = PMSignalState;
1815
-
1816
- param->PostmasterPid = PostmasterPid;
1817
- param->PgStartTime = PgStartTime;
1818
- param->PgReloadTime = PgReloadTime;
1819
- param->first_syslogger_file_time = first_syslogger_file_time;
1820
-
1821
- param->redirection_done = redirection_done;
1822
- param->IsBinaryUpgrade = IsBinaryUpgrade;
1823
- param->query_id_enabled = query_id_enabled;
1824
- param->max_safe_fds = max_safe_fds;
1825
-
1826
- param->MaxBackends = MaxBackends;
1827
-
1828
- #ifdef WIN32
1829
- param->PostmasterHandle = PostmasterHandle;
1830
- if (!write_duplicated_handle(&param->initial_signal_pipe,
1831
- pgwin32_create_signal_listener(childPid),
1832
- childProcess))
1833
- return false;
1834
- #else
1835
- memcpy(&param->postmaster_alive_fds, &postmaster_alive_fds,
1836
- sizeof(postmaster_alive_fds));
1837
- #endif
1838
-
1839
- memcpy(&param->syslogPipe, &syslogPipe, sizeof(syslogPipe));
1840
-
1841
- strlcpy(param->my_exec_path, my_exec_path, MAXPGPATH);
1842
-
1843
- strlcpy(param->pkglib_path, pkglib_path, MAXPGPATH);
1844
-
1845
- return true;
1846
- }
1847
-
1848
-
1849
- #ifdef WIN32
1850
- /*
1851
- * Duplicate a handle for usage in a child process, and write the child
1852
- * process instance of the handle to the parameter file.
1853
- */
1854
- static bool
1855
- write_duplicated_handle(HANDLE *dest, HANDLE src, HANDLE childProcess)
1856
- {
1857
- HANDLE hChild = INVALID_HANDLE_VALUE;
1858
-
1859
- if (!DuplicateHandle(GetCurrentProcess(),
1860
- src,
1861
- childProcess,
1862
- &hChild,
1863
- 0,
1864
- TRUE,
1865
- DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS))
1866
- {
1867
- ereport(LOG,
1868
- (errmsg_internal("could not duplicate handle to be written to backend parameter file: error code %lu",
1869
- GetLastError())));
1870
- return false;
1871
- }
1872
-
1873
- *dest = hChild;
1874
- return true;
1875
- }
1876
-
1877
- /*
1878
- * Duplicate a socket for usage in a child process, and write the resulting
1879
- * structure to the parameter file.
1880
- * This is required because a number of LSPs (Layered Service Providers) very
1881
- * common on Windows (antivirus, firewalls, download managers etc) break
1882
- * straight socket inheritance.
1883
- */
1884
- static bool
1885
- write_inheritable_socket(InheritableSocket *dest, SOCKET src, pid_t childpid)
1886
- {
1887
- dest->origsocket = src;
1888
- if (src != 0 && src != PGINVALID_SOCKET)
1889
- {
1890
- /* Actual socket */
1891
- if (WSADuplicateSocket(src, childpid, &dest->wsainfo) != 0)
1892
- {
1893
- ereport(LOG,
1894
- (errmsg("could not duplicate socket %d for use in backend: error code %d",
1895
- (int) src, WSAGetLastError())));
1896
- return false;
1897
- }
1898
- }
1899
- return true;
1900
- }
1901
-
1902
- /*
1903
- * Read a duplicate socket structure back, and get the socket descriptor.
1904
- */
1905
- static void
1906
- read_inheritable_socket(SOCKET *dest, InheritableSocket *src)
1907
- {
1908
- SOCKET s;
1909
-
1910
- if (src->origsocket == PGINVALID_SOCKET || src->origsocket == 0)
1911
- {
1912
- /* Not a real socket! */
1913
- *dest = src->origsocket;
1914
- }
1915
- else
1916
- {
1917
- /* Actual socket, so create from structure */
1918
- s = WSASocket(FROM_PROTOCOL_INFO,
1919
- FROM_PROTOCOL_INFO,
1920
- FROM_PROTOCOL_INFO,
1921
- &src->wsainfo,
1922
- 0,
1923
- 0);
1924
- if (s == INVALID_SOCKET)
1925
- {
1926
- write_stderr("could not create inherited socket: error code %d\n",
1927
- WSAGetLastError());
1928
- exit(1);
1929
- }
1930
- *dest = s;
1931
-
1932
- /*
1933
- * To make sure we don't get two references to the same socket, close
1934
- * the original one. (This would happen when inheritance actually
1935
- * works..
1936
- */
1937
- closesocket(src->origsocket);
1938
- }
1939
- }
1940
- #endif
1941
-
1942
- static void
1943
- read_backend_variables(char *id, Port *port)
1944
- {
1945
- BackendParameters param;
1946
-
1947
- #ifndef WIN32
1948
- /* Non-win32 implementation reads from file */
1949
- FILE *fp;
1950
-
1951
- /* Open file */
1952
- fp = AllocateFile(id, PG_BINARY_R);
1953
- if (!fp)
1954
- {
1955
- write_stderr("could not open backend variables file \"%s\": %s\n",
1956
- id, strerror(errno));
1957
- exit(1);
1958
- }
1959
-
1960
- if (fread(&param, sizeof(param), 1, fp) != 1)
1961
- {
1962
- write_stderr("could not read from backend variables file \"%s\": %s\n",
1963
- id, strerror(errno));
1964
- exit(1);
1965
- }
1966
-
1967
- /* Release file */
1968
- FreeFile(fp);
1969
- if (unlink(id) != 0)
1970
- {
1971
- write_stderr("could not remove file \"%s\": %s\n",
1972
- id, strerror(errno));
1973
- exit(1);
1974
- }
1975
- #else
1976
- /* Win32 version uses mapped file */
1977
- HANDLE paramHandle;
1978
- BackendParameters *paramp;
1979
-
1980
- #ifdef _WIN64
1981
- paramHandle = (HANDLE) _atoi64(id);
1982
- #else
1983
- paramHandle = (HANDLE) atol(id);
1984
- #endif
1985
- paramp = MapViewOfFile(paramHandle, FILE_MAP_READ, 0, 0, 0);
1986
- if (!paramp)
1987
- {
1988
- write_stderr("could not map view of backend variables: error code %lu\n",
1989
- GetLastError());
1990
- exit(1);
1991
- }
1992
-
1993
- memcpy(&param, paramp, sizeof(BackendParameters));
1994
-
1995
- if (!UnmapViewOfFile(paramp))
1996
- {
1997
- write_stderr("could not unmap view of backend variables: error code %lu\n",
1998
- GetLastError());
1999
- exit(1);
2000
- }
2001
-
2002
- if (!CloseHandle(paramHandle))
2003
- {
2004
- write_stderr("could not close handle to backend parameter variables: error code %lu\n",
2005
- GetLastError());
2006
- exit(1);
2007
- }
2008
- #endif
2009
-
2010
- restore_backend_variables(&param, port);
2011
- }
2012
-
2013
- /* Restore critical backend variables from the BackendParameters struct */
2014
- static void
2015
- restore_backend_variables(BackendParameters *param, Port *port)
2016
- {
2017
- memcpy(port, &param->port, sizeof(Port));
2018
- read_inheritable_socket(&port->sock, &param->portsocket);
2019
-
2020
- SetDataDir(param->DataDir);
2021
-
2022
- memcpy(&ListenSocket, &param->ListenSocket, sizeof(ListenSocket));
2023
-
2024
- MyCancelKey = param->MyCancelKey;
2025
- MyPMChildSlot = param->MyPMChildSlot;
2026
-
2027
- #ifdef WIN32
2028
- ShmemProtectiveRegion = param->ShmemProtectiveRegion;
2029
- #endif
2030
- UsedShmemSegID = param->UsedShmemSegID;
2031
- UsedShmemSegAddr = param->UsedShmemSegAddr;
2032
-
2033
- ShmemLock = param->ShmemLock;
2034
- ShmemVariableCache = param->ShmemVariableCache;
2035
- ShmemBackendArray = param->ShmemBackendArray;
2036
-
2037
- #ifndef HAVE_SPINLOCKS
2038
- SpinlockSemaArray = param->SpinlockSemaArray;
2039
- #endif
2040
- NamedLWLockTrancheRequests = param->NamedLWLockTrancheRequests;
2041
- NamedLWLockTrancheArray = param->NamedLWLockTrancheArray;
2042
- MainLWLockArray = param->MainLWLockArray;
2043
- ProcStructLock = param->ProcStructLock;
2044
- ProcGlobal = param->ProcGlobal;
2045
- AuxiliaryProcs = param->AuxiliaryProcs;
2046
- PreparedXactProcs = param->PreparedXactProcs;
2047
- PMSignalState = param->PMSignalState;
2048
-
2049
- PostmasterPid = param->PostmasterPid;
2050
- PgStartTime = param->PgStartTime;
2051
- PgReloadTime = param->PgReloadTime;
2052
- first_syslogger_file_time = param->first_syslogger_file_time;
2053
-
2054
- redirection_done = param->redirection_done;
2055
- IsBinaryUpgrade = param->IsBinaryUpgrade;
2056
- query_id_enabled = param->query_id_enabled;
2057
- max_safe_fds = param->max_safe_fds;
2058
-
2059
- MaxBackends = param->MaxBackends;
2060
-
2061
- #ifdef WIN32
2062
- PostmasterHandle = param->PostmasterHandle;
2063
- pgwin32_initial_signal_pipe = param->initial_signal_pipe;
2064
- #else
2065
- memcpy(&postmaster_alive_fds, &param->postmaster_alive_fds,
2066
- sizeof(postmaster_alive_fds));
2067
- #endif
2068
-
2069
- memcpy(&syslogPipe, &param->syslogPipe, sizeof(syslogPipe));
2070
-
2071
- strlcpy(my_exec_path, param->my_exec_path, MAXPGPATH);
2072
-
2073
- strlcpy(pkglib_path, param->pkglib_path, MAXPGPATH);
2074
-
2075
- /*
2076
- * We need to restore fd.c's counts of externally-opened FDs; to avoid
2077
- * confusion, be sure to do this after restoring max_safe_fds. (Note:
2078
- * BackendInitialize will handle this for port->sock.)
2079
- */
2080
- #ifndef WIN32
2081
- if (postmaster_alive_fds[0] >= 0)
2082
- ReserveExternalFD();
2083
- if (postmaster_alive_fds[1] >= 0)
2084
- ReserveExternalFD();
2085
- #endif
2086
- }
2087
-
2088
-
2089
- Size
2090
- ShmemBackendArraySize(void)
2091
- {
2092
- return mul_size(MaxLivePostmasterChildren(), sizeof(Backend));
2093
- }
2094
-
2095
- void
2096
- ShmemBackendArrayAllocation(void)
2097
- {
2098
- Size size = ShmemBackendArraySize();
2099
-
2100
- ShmemBackendArray = (Backend *) ShmemAlloc(size);
2101
- /* Mark all slots as empty */
2102
- memset(ShmemBackendArray, 0, size);
2103
- }
2104
-
2105
- static void
2106
- ShmemBackendArrayAdd(Backend *bn)
2107
- {
2108
- /* The array slot corresponding to my PMChildSlot should be free */
2109
- int i = bn->child_slot - 1;
2110
-
2111
- Assert(ShmemBackendArray[i].pid == 0);
2112
- ShmemBackendArray[i] = *bn;
2113
- }
2114
-
2115
- static void
2116
- ShmemBackendArrayRemove(Backend *bn)
2117
- {
2118
- int i = bn->child_slot - 1;
2119
-
2120
- Assert(ShmemBackendArray[i].pid == bn->pid);
2121
- /* Mark the slot as empty */
2122
- ShmemBackendArray[i].pid = 0;
2123
- }
2124
- #endif /* EXEC_BACKEND */
2125
-
2126
-
2127
- #ifdef WIN32
2128
-
2129
- /*
2130
- * Subset implementation of waitpid() for Windows. We assume pid is -1
2131
- * (that is, check all child processes) and options is WNOHANG (don't wait).
2132
- */
2133
- static pid_t
2134
- waitpid(pid_t pid, int *exitstatus, int options)
2135
- {
2136
- win32_deadchild_waitinfo *childinfo;
2137
- DWORD exitcode;
2138
- DWORD dwd;
2139
- ULONG_PTR key;
2140
- OVERLAPPED *ovl;
2141
-
2142
- /* Try to consume one win32_deadchild_waitinfo from the queue. */
2143
- if (!GetQueuedCompletionStatus(win32ChildQueue, &dwd, &key, &ovl, 0))
2144
- {
2145
- errno = EAGAIN;
2146
- return -1;
2147
- }
2148
-
2149
- childinfo = (win32_deadchild_waitinfo *) key;
2150
- pid = childinfo->procId;
2151
-
2152
- /*
2153
- * Remove handle from wait - required even though it's set to wait only
2154
- * once
2155
- */
2156
- UnregisterWaitEx(childinfo->waitHandle, NULL);
2157
-
2158
- if (!GetExitCodeProcess(childinfo->procHandle, &exitcode))
2159
- {
2160
- /*
2161
- * Should never happen. Inform user and set a fixed exitcode.
2162
- */
2163
- write_stderr("could not read exit code for process\n");
2164
- exitcode = 255;
2165
- }
2166
- *exitstatus = exitcode;
2167
-
2168
- /*
2169
- * Close the process handle. Only after this point can the PID can be
2170
- * recycled by the kernel.
2171
- */
2172
- CloseHandle(childinfo->procHandle);
2173
-
2174
- /*
2175
- * Free struct that was allocated before the call to
2176
- * RegisterWaitForSingleObject()
2177
- */
2178
- pfree(childinfo);
2179
-
2180
- return pid;
2181
- }
2182
-
2183
- /*
2184
- * Note! Code below executes on a thread pool! All operations must
2185
- * be thread safe! Note that elog() and friends must *not* be used.
2186
- */
2187
- static void WINAPI
2188
- pgwin32_deadchild_callback(PVOID lpParameter, BOOLEAN TimerOrWaitFired)
2189
- {
2190
- /* Should never happen, since we use INFINITE as timeout value. */
2191
- if (TimerOrWaitFired)
2192
- return;
2193
-
2194
- /*
2195
- * Post the win32_deadchild_waitinfo object for waitpid() to deal with. If
2196
- * that fails, we leak the object, but we also leak a whole process and
2197
- * get into an unrecoverable state, so there's not much point in worrying
2198
- * about that. We'd like to panic, but we can't use that infrastructure
2199
- * from this thread.
2200
- */
2201
- if (!PostQueuedCompletionStatus(win32ChildQueue,
2202
- 0,
2203
- (ULONG_PTR) lpParameter,
2204
- NULL))
2205
- write_stderr("could not post child completion status\n");
2206
-
2207
- /* Queue SIGCHLD signal. */
2208
- pg_queue_signal(SIGCHLD);
2209
- }
2210
- #endif /* WIN32 */
2211
-
2212
- /*
2213
- * Initialize one and only handle for monitoring postmaster death.
2214
- *
2215
- * Called once in the postmaster, so that child processes can subsequently
2216
- * monitor if their parent is dead.
2217
- */
2218
- #ifndef WIN32
2219
- #else
2220
- #endif /* WIN32 */