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 1w4s2i-002dgn-1C for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Mar 2026 03:02:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w4s2e-003m4J-2v for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Mar 2026 03:02:53 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w4s2e-003m4B-22 for pgsql-hackers@lists.postgresql.org; Tue, 24 Mar 2026 03:02:53 +0000 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w4s2c-00000000nyI-1SFH for pgsql-hackers@lists.postgresql.org; Tue, 24 Mar 2026 03:02:52 +0000 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-2ad21f437eeso42705075ad.0 for ; Mon, 23 Mar 2026 20:02:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774321368; x=1774926168; 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=bqSxgcyxpE6LwtKhpxBxeNRQgzABREZ83VpfoBW0Kj4=; b=E0YdKun3/xXM+xBwaQLemmrIjG+2sHv3ixx0I+2e1M8hKJa3HC9adGmlNWHfilz8pe zOnQ+uF5apXi+qFcwRZyBHnaWBag1OwblUxGfXiutCqRvMJPPiusMtm46AntKYf5wQnc SqoG7NEzf6mVprObBN0fWpalqPBhi0YklVbHgyfqrSVnrZENtd1R+2FIK/B+IZX/WJSU ZoYxio1y6M3F0JC9Ne3Z4EINH0j/3R0fXzypfz+E6JCv+SWlKwahoPIZRQJeB0GD9sCy 0IG3ipv2Hju7Wxi4sgRvDVKKItRlVL+pDPKZqBdb64Zb9F5lS82UTsvyuQjwme0bVBLS qBTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774321368; x=1774926168; 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=bqSxgcyxpE6LwtKhpxBxeNRQgzABREZ83VpfoBW0Kj4=; b=g8RM6125oZ23JjXfaHPic/KtI0HBoUkdRqXirhrsyJq2YOwvqeJ77vNcq5o7rRPute LGs5dJTv+X8e6GCtsUHEooIhWLeBNfXwbxZT2fMTQev9SK14ZVvUkkhGxJh9wH5JQvJg g9I3b3f2Ul6DTf4WgQca1iOIv+5rPbAdfXEsRQNlaO1b6j0koDmGLaNQP9KNaKkJeT9y hBnw6pPloUrzI+ROuUaHQbB1wTTigcQrg9+7TfZGbt7x8/A1wk+r4aM7t2kRUf4uFiJu ycw5d2E9I/5s3KbHyIzhogAwQlypKWOxnGL96aCklqRjRz1w0dlA7UeohyWAhhDfb49I uqHQ== X-Forwarded-Encrypted: i=1; AJvYcCXVpjE0A/1XS/vJvYr03ds9thsIPPMTtbpt6rnMQN6Q3j9Icc0vVDX0zryBtPH8PQJw5ECsIv8o9wNDyqcQ@lists.postgresql.org X-Gm-Message-State: AOJu0YwSrlAppZWmhKbQ3t902zxeROW7nJ6cupYzxsFuZhJ9ry9/7YTX cNAUC9ct9yFeoKFtb2osQ1wvw8kI7cg9OlllXdycXhzsVhWw8jVN5jy4 X-Gm-Gg: ATEYQzytIPw5161vKmyPaPbrMK/wtkkRqwagmuYuw/u167jnZwbwEaCTnYX+rw7AehG tmUkAnOeNW54m90BeRy4V/dM89w67k2ryCkumR9zTNIeBlFfOZOO3eJhK8R+Jb+5okpkuPxVGZ7 pv8hsA4YExOGFpsYST/rJ9gKH+cRqPl9/Lz2jeg4VVHXSQK3dICWzIAq8u1n6cbzprJUuudOX6z zXtOp7w3mcXGYy0lvBT95/GKtJcocNDhl4vKqOLj7kSX9RJ+WRvhHJQZRR02RPRk9KM+Ofginrt JJSi3EZTwg0SmzrKF8rxYJsd6hYRHE8gbGRD37LeZWx2SbY5+I05+HI15eSRcivulMjkIPzgtZA yEvtN75783S8YTClvJ7Hm+rx846n2PN8s5lIYp0abAWLdtU0BeM9C40JPLyfVZkUdvWOi4RgNp9 fOtkRlFAyd39iiH45QN7IUWz1tA3JLxh4= X-Received: by 2002:a17:902:d487:b0:2ae:be67:722f with SMTP id d9443c01a7336-2b0a4e355b9mr15954575ad.22.1774321368030; Mon, 23 Mar 2026 20:02:48 -0700 (PDT) Received: from smtpclient.apple ([103.62.49.186]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b08352a17asm123335495ad.24.2026.03.23.20.02.44 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Mar 2026 20:02:47 -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:02:12 +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 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. 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 > > 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! I verified with v17, %m works now. >=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? I personally prefer to keep those prefixes, which helps keep the log = messages in a consistent style. >=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; + } ``` 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. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/