Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w4sUa-002eDz-0M for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Mar 2026 03:31:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w4sUY-003vjn-1y for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Mar 2026 03:31:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w4sUY-003vjL-0g for pgsql-hackers@lists.postgresql.org; Tue, 24 Mar 2026 03:31:42 +0000 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w4sUW-00000000j70-2Wuk for pgsql-hackers@lists.postgresql.org; Tue, 24 Mar 2026 03:31:41 +0000 Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-c742d7c8acfso344410a12.1 for ; Mon, 23 Mar 2026 20:31:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774323099; x=1774927899; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=sxqP246y4HTK4L1XqRriOE/BfZRmj0ATzO+TVMHq94w=; b=T6NyOlMbUxd3rUvThlb+ISJZ10a/MVvBceAoojw7E/JfBU7a01xTtsDqmwWjP5kELR hY4OfxFzAFmpeZgwjC2HujvOeI4GYUogOb0f6aRrcCL1vrfPEyhqQ/whwjDJzrGhj7+K Ywc4rV+6F200LcEQcqgimWkbt5PtYyYDHcJCscY2PDRQ/BsyTyHj3QC8ODoKG/tFn9sz FZzUD1nT6gprQGrha42/p/YNU/9oFrerEHwAHL7NFTyupmLI35mr4gKH4qwQpuz9x9OK NgYqdt7JO08u927+p0HeaqlrCLSysVEdIswBOfYjgJrwyPBKwCP/RNeB4zy7qzmhzlud +cag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774323099; x=1774927899; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=sxqP246y4HTK4L1XqRriOE/BfZRmj0ATzO+TVMHq94w=; b=qKvdThoYL3Yp+2YyHw4dRBF1B+ZEXpbI5KmJDgH9x4p6CduriyqeDsjXvJPn2c48YH sTrFWXxHviltm6hk17xENul3+sPD/rZTycIWDVmEbpqLNv41Dd4N/uaCEgfh9+VCiMyc Wp1cTKGZITKPhzCh3+zt/pP2Pr1upxt6bQgOy71Oz2LLz14L8gmDCxCZ1yNgCV41Rgzy 1ud+HrRT6s2i11WXQskf9pV6b/fKBIctWG81td1cdjtHdf3v6tpo3PogWDz/BJI5ujNb PFdHMVyEGhti5grywweylNloFvnS6qchHhH7H8jUfjhpXISR2TRReXWhWa5eyZnWC4Lw qbyQ== X-Forwarded-Encrypted: i=1; AJvYcCWA20WNNtC3WdCC7nxE8kCTHAMaRpkRjoDzq1s7YZ8YhYv6C4IbYSLXyCwKsronjq6HqW0vsp/P9frPNZgK@lists.postgresql.org X-Gm-Message-State: AOJu0YznOsoErqgH24Qnc71YmY+0QittkyN0c9jVhmvWGmt/NL2XF1cM M71E692/gA/V6eqhAgdDvF6+dLcv7xKjXmTSzfBsJcNb9O8VGm0zNqPM X-Gm-Gg: ATEYQzxfwhks9IhRttBXplp348pSm2TeO5+hSzqYkSblDjAp7P0GaxFGpd6+Bhwan7B skP+25cUHTP3MuMX31sdJd3cnVNxxINwRdp3mjvTYcKUb+uxrdxB9hArUAG9woN7qa2faNrJLQ+ WDTmMNSkvPA/qa5jqV+fAp93+QHepLT/geJf7jcaP/0T5JDdYFd/F8iWOHMk+kCO2XeJyqoXT8n tyN6N14PGBgHJTZzXgZy4+nW+kbfWu5bSuqNwJjBfXIiQpVAKKaYhNzAEnXwQDYYb50YyE9aMSG bOPUA4H4m+9ebjGbTCuhxFeV6puOwIpOJRlMfMzcgnx+eIdaPccbsMI+1vQFLX+ScjZ0xSyjop7 +jVeW/SZ3hkPBVNsuUORuaJVwlsASJiAzpWZnyv4oUkcZ7nL08yjLkfte1vZ1HffhkrkoXwYImo +Y8dfZiEnVG1wB2Qk1Jwufn38aMmcjS5w= X-Received: by 2002:a17:902:d488:b0:2b0:6d2d:f1d5 with SMTP id d9443c01a7336-2b0827c2c55mr132802215ad.45.1774323099507; Mon, 23 Mar 2026 20:31:39 -0700 (PDT) Received: from smtpclient.apple ([103.62.49.186]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b08354b109sm169859275ad.31.2026.03.23.20.31.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Mar 2026 20:31:38 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: Re: [Proposal] Adding Log File Capability to pg_createsubscriber From: Chao Li In-Reply-To: Date: Tue, 24 Mar 2026 11:31:02 +0800 Cc: =?utf-8?B?Ikt1cm9kYSwgSGF5YXRvL+m7kueUsCDpmrzkuroi?= , Amit Kapila , shveta malik , Shlok Kyal , vignesh C , Euler Taveira , "pgsql-hackers@lists.postgresql.org" , Peter Smith Content-Transfer-Encoding: quoted-printable Message-Id: References: To: Gyan Sreejith X-Mailer: Apple Mail (2.3864.400.21) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Mar 24, 2026, at 11:02, Chao Li wrote: >=20 >=20 >=20 >> On Mar 24, 2026, at 09:23, Gyan Sreejith = wrote: >>=20 >> On Mon, Mar 23, 2026 at 2:24=E2=80=AFAM Chao Li = wrote: >> + /* Build timestamp directory path */ >> + len =3D snprintf(logdir, MAXPGPATH, "%s/%s", log_basedir, = timestamp); >> + >> + if (len >=3D MAXPGPATH) >> + pg_fatal("directory path for log files, %s/%s, is too = long", >> + logdir, timestamp); >> ``` >>> In the pg_fatal call, I believe logdir should be log_basedir. >> We are writing into logdir, and the if will be true only if it is too = long. Hence we should be checking logdir. >=20 > Not sure if I stated my comment clearly. The =E2=80=9Clogdir=E2=80=9D = is build from (=E2=80=9C%s/%s, log_basedir, timestamp), however, in the = pg_fatal, you are printing (=E2=80=9C%s/%s=E2=80=9D, logdir, timestamp), = here logdir has included a truncated timestamp as it is too long, and so = the fatal message will be = =E2=80=9Clog_basedir/truncated-timestamp/timestamp=E2=80=9D. So the = pg_fatal should be: > ``` > report_createsub_fatal("directory path for log files, %s/%s, is = too long=E2=80=9D, > log_basedir, timestamp); > ``` >=20 >>=20 >>> The biggest problem I see with this patch is here. = internal_log_file_write doesn=E2=80=99t handle =E2=80=9C%m=E2=80=9D. I = think we can check the implementation of pg_log_generic_v how %m is = handled. The key code snippet is: >> ``` >>> errno =3D save_errno; >>=20 >>> va_copy(ap2, ap); >>> required_len =3D vsnprintf(NULL, 0, fmt, ap2) + 1; >>> va_end(ap2); >> ``` >>> Where, vsnprintf points to pg_vsnprintf, and pg_vsnprintf calls dopr = to handle %m. >> I have saved and restored errno similar to that. The code snippet you = pointed out is, as far as I understand, where they are calculating how = much space to allocate (including the \0 at the end). I think it will be = handled automatically as long as errno is not overwritten - which it = will now be. Thank you! >=20 > I verified with v17, %m works now. >=20 >>=20 >>> The other problem is, with internal_log_file_write, HINT, DETAIL = prefix are no longer printed, is that intentional? >> I could add a switch-case to print it out. Is that important? What do = you think? >=20 > I personally prefer to keep those prefixes, which helps keep the log = messages in a consistent style. >=20 >>=20 >> >=20 > One comment on v17. > ``` > + if (internal_log_file_fp !=3D NULL) > + { > + if (fclose(internal_log_file_fp) !=3D 0) > + report_createsub_fatal("could not close %s/%s.log: %m", logdir, = INTERNAL_LOG_FILE_NAME); > + internal_log_file_fp =3D NULL; > + } > ``` >=20 > As the error is about internal_log_file_fp, meaning it may no longer = able to write to internal_log_file_fp anymore, we should avoid use = report_createsub_fatal to log the error again. Maybe just a pg_fatal(), = or just log to stderr. >=20 I forgot to mention one small suggestion. Since the internal log file path includes a timestamped directory, it is = a bit inconvenient to figure out the full path of the file after the = command finishes. I think it would be helpful to print the full path of = the internal log file at the end, something like: ``` if (internal_log_file_fp !=3D NULL) { if (fclose(internal_log_file_fp) !=3D 0) report_createsub_fatal("could not close = %s/%s.log: %m", logdir, INTERNAL_LOG_FILE_NAME); internal_log_file_fp =3D NULL; printf("check the internal log file at \"%s/%s.log\"", = logdir, INTERNAL_LOG_FILE_NAME); } ``` Note that I used printf() here, because based on my test, pg_log_info() = does not work in this place. The other thing I noticed while trying the above code is that = cleanup_objects_atexit() has this: ``` if (success) return; ``` That means on the success path, internal_log_file_fp will not be closed. = So this part would need some adjustment as well. Maybe one way is to = jump to the log-file cleanup part before returning, for example with a = goto, so that internal_log_file_fp is always closed. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/