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 1vlku9-003Zpu-2I for pgsql-hackers@arkaria.postgresql.org; Fri, 30 Jan 2026 09:35:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vlku7-0048Ws-2L for pgsql-hackers@arkaria.postgresql.org; Fri, 30 Jan 2026 09:35:04 +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 1vlku7-0048Wk-1H for pgsql-hackers@lists.postgresql.org; Fri, 30 Jan 2026 09:35:04 +0000 Received: from mail-yw1-x1133.google.com ([2607:f8b0:4864:20::1133]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vlku5-00000000Amp-3u4C for pgsql-hackers@lists.postgresql.org; Fri, 30 Jan 2026 09:35:03 +0000 Received: by mail-yw1-x1133.google.com with SMTP id 00721157ae682-7945838691aso35334457b3.0 for ; Fri, 30 Jan 2026 01:35:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1769765700; cv=none; d=google.com; s=arc-20240605; b=lSWLplx5va/o7LVwF6uK76o2xVdi+Qzp881/IEfAIRqB31wxE46Fkddi9MwNn3iZzL 81H2SJ8ZU2y5W8KRbbtp04j3wyPrsPKYG9dCeTIvzFsMxnC6+seclClcspBkNDhrA9Sk cCXZfWNrdtilkyBRkn3IH1xAp2M1fhYqlGl2VAhgxS1/hRFG1qLIGfAgT1t5zqMAcP2W HmeQOrZ8H2IYd/CVoMFCVpwGlmEKmb/ssWkLN5V1AVPQE1HtwDRfCGF74KMnWo1Ql9Dr NzIHH2lnsggfCs3+B7C6+UIVqYQ39g429EyIKbmXM4qjHUCpHWu7hzzkuxn7t0LnDXoV Zd5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=gqWSkM5GlQTbY4NAc1jiPtpQwldIXOtOj3BC/B2bS18=; fh=sAGg5G9vBlwOXziObXYnKFclh8rqNqNvMkb3w5NoyVE=; b=KTzduyhJLJkKkPBqZhMMmZPAbrKFlZXD8yod0sovHqIV9gutfx6vdoQGW67It800yL nU3kvQg6NutYbGzmtXAqgvEwEUviOBxxDjWuYPgU2fHDZqWE6I0EZ5dB10r4bZqEjvV+ 06qBc8Yc8d2LvHZeusirS1MAgynddTw7GjuM2nNx/HBSnlRy3M326H9EzyRkl2a5hvm/ HjCI0LRJoDiX62N/H5QxWKyF2T00qTcH+2My8rGcAoMWdQ+x2+CbXhxqx5bmEQ7K5+J/ SmFUbnB2yPnIM1fOwS6yV3mdWNwcwYgzj+aa7ttolBvX/JYv8M9frddaQSTpusMYPxfQ CXRA==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769765700; x=1770370500; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=gqWSkM5GlQTbY4NAc1jiPtpQwldIXOtOj3BC/B2bS18=; b=OG0xSVhj1B+19/x/KXA704Kut41pGOyNVSgb3TlFk3jgGO6BlkEycA80CFWTouaRsm G+b+h/qvOkJ3eUSn2kSbu+gqCNNHda3z/8JWv8VIglxpUSF65Hpn09LaJ3Uwd84+fIAs zk3u1k30/cFwYK91RHwLMfr0KeVfncNm3vG3dqvmgtP91aW4k+D6qwdwwUfZsVRdgqfX gMss3jWM6gqBS+C5nD362d/Emg4zX3xzl3tI6PEIGfamB3dpnWXeJDjGqlmSos3Ur4XG EIQ07iaRw3I+jwJ98w43BHty9IaHC5NGGB7RXfEI+t17cm1a7yvPlHweEpxiYB5iYHC2 jjiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769765700; x=1770370500; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=gqWSkM5GlQTbY4NAc1jiPtpQwldIXOtOj3BC/B2bS18=; b=SYyWYIkl4WUGHnLygju6r4HxgIPhK+P0ZWOjarV2fwQxIyntas7uLzcJXag7Da23/i d2EXyL1IkEnpVMifN0tAxHTtdkoQ/Jzxl1GtEVQQKHBeafk4q30tE6NRmSk8SdxD3uP0 I21NZhlQgAWd1/4//rjfeo8iGgo+uWAg0UAQTaHHtPp7U2zanPHIzVnDPORKwypkxJvj ASTo3+/CRqyYdmFi0UNRy/viRjBg/vA2pXPMoQHyzbd9kmLD1B4ayPQ4NnMUD0u1lo/x Pd0XTpDbb2liGGu79Siim4YfK8yN7+EWstwWsgFG/4gbw4/MDFRzgFXgoUeIQcmDmRde DRrQ== X-Forwarded-Encrypted: i=1; AJvYcCWD68tWG6IrSU9GYZ12jhh8Hm7Z5VPZru+8n2Ug+hUP6TChVo751MBCN7hKb54eVMdp9V8Z1j7xJZGQOIr5@lists.postgresql.org X-Gm-Message-State: AOJu0Yw7R3f3mWBzkKomLHl5/T1Tg1RgyK/dhpqSzj/Gy+oM6Q2RRltD szZWIFHy/vzwvUVXqVLpXyuwuNcj+7GwPU5iXrkp48xxZwPGAaaM6vAnkqgV36mV6PVD2HtauRr IeNVZVfUhpJ+pbEPzAG8qYUKrzH+RNWk= X-Gm-Gg: AZuq6aI/Ihah3vQWXr5SGRR9IxrEZi0GTc3SoprO6B2ipoTuzB4vre0mw7cED1nvfcD OL3Q528AG29v+XoVGuKhA5s+3CKownL72lcRXBx3yL2y+j0YnM0MxRR3Rq2K7zFOTvNPtJNpEpH ImNhb2DRA+e6FJZPGA3Xj/v6goejdVyyrZ4XSh/yJ25MUcRgcKIsAoc9USYuAzgUAyGMNxxNUxn FF0xUf2bP7Dn6Fsdam5ZSOiGsgJAv5cJczkwOjrLcfQGGmqriRJ2iOuUHvcJwU/j2jG8C+WoeD1 1TZ9Og7Y X-Received: by 2002:a05:690e:130e:b0:649:6a7f:1da3 with SMTP id 956f58d0204a3-6499efff4fdmr4344848d50.18.1769765699993; Fri, 30 Jan 2026 01:34:59 -0800 (PST) MIME-Version: 1.0 References: <48261e54-c4f1-4bde-a4a9-4f3698a6b380@app.fastmail.com> In-Reply-To: From: vignesh C Date: Fri, 30 Jan 2026 15:04:48 +0530 X-Gm-Features: AZwV_Qi7534RIjctdHVq7-ADmVS_BPQ_xnxWgEzMwe14QtwZahWMnjoi6ZgJWfM Message-ID: Subject: Re: [Proposal] Adding Log File Capability to pg_createsubscriber To: Gyan Sreejith Cc: Amit Kapila , Euler Taveira , "kuroda.hayato@fujitsu.com" , "pgsql-hackers@lists.postgresql.org" , Peter Smith Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 26 Jan 2026 at 07:08, Gyan Sreejith wrote: > > Thank you, I have made the changes and attached the patch. Few comments: 1) Adding \n at the end will assert as pg_log_generic_v has the following Assert: Assert(fmt[strlen(fmt) - 1] != '\n'); @@ -1106,7 +1220,7 @@ check_subscriber(const struct LogicalRepInfo *dbinfo) int max_reporigins; int max_wprocs; - pg_log_info("checking settings on subscriber"); + INFO("checking settings on subscriber\n"); You can run in verbose mode without -l to see this issue 2) There is a chance that directory creation can fail, it should be checked and error should be thrown: + if (stat(opt.log_dir, &statbuf) != 0) + { + if (errno == ENOENT) + { + mkdir(opt.log_dir, S_IRWXU); + INFO("log directory created"); 3) Can you include an fflush after the fprintf so that there is no log content lost in case of abrupt failure: + va_start(args, format); + vfprintf(internal_log_file_fp, format, args); + fprintf(internal_log_file_fp, "\n"); + va_end(args); 4) Since you are closing the log file early, the logs after this point like the drop publication/drop replication slot in error flow will be lost. They will neither appear in the console nor in the log file: * Clean up objects created by pg_createsubscriber. @@ -212,6 +315,9 @@ cleanup_objects_atexit(void) if (success) return; + if (internal_log_file_fp != NULL) + fclose(internal_log_file_fp); + 5) Since there is only one caller for this function and not needed by anyone else, this code can be moved to the caller: +static void +populate_timestamp(char *timestr, size_t ts_len) +{ + struct timeval tval; + time_t now; + struct tm tmbuf; + + gettimeofday(&tval, NULL); + + /* + * MSVC's implementation of timeval uses a long for tv_sec, however, + * localtime() expects a time_t pointer. Here we'll assign tv_sec to a + * local time_t variable so that we pass localtime() the correct pointer + * type. + */ + now = tval.tv_sec; + strftime(timestr, ts_len, + "%Y-%m-%d-%H-%M-%S", + localtime_r(&now, &tmbuf)); + /* append microseconds */ + snprintf(timestr + strlen(timestr), ts_len - strlen(timestr), + ".%06u", (unsigned int) (tval.tv_usec)); +} Regards, Vignesh