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.94.2) (envelope-from ) id 1stC7d-00EHQh-Ty for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Sep 2024 20:26:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1stC7b-00DmNd-3w for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Sep 2024 20:26:55 +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.94.2) (envelope-from ) id 1stC7a-00DmNV-OC for pgsql-hackers@lists.postgresql.org; Tue, 24 Sep 2024 20:26:54 +0000 Received: from mail-io1-xd2c.google.com ([2607:f8b0:4864:20::d2c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1stC7W-000tmR-DR for pgsql-hackers@postgresql.org; Tue, 24 Sep 2024 20:26:54 +0000 Received: by mail-io1-xd2c.google.com with SMTP id ca18e2360f4ac-82aa7c3b482so234578039f.2 for ; Tue, 24 Sep 2024 13:26:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727209610; x=1727814410; darn=postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=BMvhykAHZOxReHolnL06sKtZmKb0j7Go+dQdToBNlMk=; b=MZX/2R3IjoI7BvrJ5YSiYFMxvHeZfcfnJb7A4eHbQjtDd2xC0SfLrsnDtAoxviVk6E p4JXJwtwY4+Wwqi4U99F5y7Y4xXmIcb+ZqzSWXc+pVyMGsX1dy0sukTtJWXp2uvNhdcJ JWsWcSAcxwYUze15AQP29XFfIi78j/GaFOZ84R3caqebpO/Xwgz+obCZinmJQJaXilhz MfdleoSfK0Nrq4YVL3yncB8EV+Nfct3edIu5phIwrGazt7HRacXu5C/u3ncBAjfucFGR zzN8APzyQZHWsrGzolHUpSENOCF/CZFhZe69nvje8+JxxukrpfiOE+f/xivpRGY4FHpP BTiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727209610; x=1727814410; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=BMvhykAHZOxReHolnL06sKtZmKb0j7Go+dQdToBNlMk=; b=R93EILEojaJk+WFSqdpcwRzXuFOKTmz3Hw+hm0PQ0w5cMG+x7P6tX8zqd6QdGQhYbE 1tO+DvAZtuZJ4NPUxBwg76bctQ0RFzkQQCMpVJ5gEK330bRyD5G02gyBKoPPoSifx7sD dT7iJEBmdlYjRjAcbeyjGJ117ZkoNH7CaeKOtYHIdwPJT3bYR9LTSxCls6zUm/bLGAy7 IiqlWwfhMdHb2gPFqCIYrbIPfQn128nMD1o47wYXpi4g70QjBpmfV7nh0/WOdkdb+13f GrXk7SUSSYtfpbwuz1b9R6I6VA1/iYibb6jtgc8CVwUsis4Sib0mMi0Bh95/1jAXaaoX nwiw== X-Gm-Message-State: AOJu0YzKcLO3XPnBOnEzCh+p1mCfqu/AFuI8mNQHuKi5eJWDZ97h20zX AG+Snl0XQyFHi2xt5BBLTpIFswpMKP/wG7PbJbywKEzQXgl6egzE4lUGcQ== X-Google-Smtp-Source: AGHT+IG9XA63tjpf6WlW8ftukl8ww7cDn9BtFq456e68G2RWu3ZZ2YlZy4FXPHf84AELqg4DsJbn3A== X-Received: by 2002:a05:6e02:20c8:b0:397:6dfc:993a with SMTP id e9e14a558f8ab-3a26d7bef90mr8022515ab.21.1727209609727; Tue, 24 Sep 2024 13:26:49 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4d40f14d2f1sm600476173.74.2024.09.24.13.26.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Sep 2024 13:26:49 -0700 (PDT) Date: Tue, 24 Sep 2024 15:26:47 -0500 From: Nathan Bossart To: Max Johnson Cc: "pgsql-hackers@postgresql.org" Subject: Re: pg_ctl/miscinit: print "MyStartTime" as a long long instead of long to avoid 2038 problem. Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Sep 24, 2024 at 07:33:24PM +0000, Max Johnson wrote: > I have found an instance of a time overflow with the start time that is > written in "postmaster.pid". On a 32-bit Linux system, if the system date > is past 01/19/2038, when you start Postgres with `pg_ctl start -D > {datadir} ...`, the start time will have rolled back to approximately > 1900. This is an instance of the "2038 problem". On my system, pg_ctl > will not exit if the start time has overflowed. Nice find. I think this has been the case since the start time was added to the lock files [0]. > - snprintf(buffer, sizeof(buffer), "%d\n%s\n%ld\n%d\n%s\n", > + snprintf(buffer, sizeof(buffer), "%d\n%s\n%lld\n%d\n%s\n", > amPostmaster ? (int) my_pid : -((int) my_pid), > DataDir, > - (long) MyStartTime, > + (long long) MyStartTime, > PostPortNumber, > socketDir); I think we should use INT64_FORMAT here. That'll choose the right length modifier for the platform. And I don't think we need to cast MyStartTime, since it's a pg_time_t (which is just an int64). [0] https://postgr.es/c/30aeda4 -- nathan