pg_query 4.2.1 → 6.1.0

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