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 1sUCG2-001CV4-Uy for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Jul 2024 21:32:18 +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 1sUCG0-005V64-2b for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Jul 2024 21:32:16 +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.94.2) (envelope-from ) id 1sUCFz-005V5w-N1 for pgsql-hackers@lists.postgresql.org; Wed, 17 Jul 2024 21:32:16 +0000 Received: from mail-io1-xd33.google.com ([2607:f8b0:4864:20::d33]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sUCFx-0005Ch-H9 for pgsql-hackers@postgresql.org; Wed, 17 Jul 2024 21:32:14 +0000 Received: by mail-io1-xd33.google.com with SMTP id ca18e2360f4ac-8046f65536dso4446339f.1 for ; Wed, 17 Jul 2024 14:32:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721251932; x=1721856732; 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=grPLhMYuZyFaeTXrOT5oKNfpkdvOfdpzxMHchgKtgf4=; b=fbhZ7kmb1hw5w9LkoobkE/uo2sUzmXOc+oc5aKm1nERlPKz/r9SrOCqQLqA/jXiuCW bewSj3t+85AbAl/0VwTQTtSspkcTw4qiEDPnAXqC6UNvUb99aBtMFAAVlat3IEdrMJqM JB33b1yGfJNVgeQp9T4xHSXocXntHEkCW/uERXJxPQXwe0HcFIKc5qwgDwQfY5z8FGAx j23hBsfMXX6gWPcCOwMrQRq7oh+baDSrxrURT6Yc/IZYTy1zFAqm3XsLOkKmmOkhCfB8 9GLdRn1xoXyNw8b3UOYF/QOF0iq4mz8vQ7BqhS5ysDhAuSkQvn+sjaHLEwqptMO+O+ab wuKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721251932; x=1721856732; 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=grPLhMYuZyFaeTXrOT5oKNfpkdvOfdpzxMHchgKtgf4=; b=fdDPuCkVKopamYD/X9xxcGOnmNFGTWJTwDfGqVDV/9DudVVZ5ZnUXNpoTO0TV9CGnz jHXszlu8Afa9005Z35L/DXEqR9aTTDlY/IiFp3oRYo5DD+/F+90HrainePHFXgFCu3do iAAXaIaDTd22qHSCbJcSK4fMhVMfydJIoHtzF59QXRS43dYS8BccEWmfGztr7BEfBKqF YKcAODS3TiYT3nfeLEa9LptAJjHBVqLcpwsIGsgG8rE76mQR2SRHALDY6GpQfxpYP0w8 PsRkqyCef7WmthUWyWeKvu4gM5T4FgSdxtTqAABFdO9veY1sBP0+vRtTR0isOuq+Ocai ddGw== X-Forwarded-Encrypted: i=1; AJvYcCVEHZdMcU/JSEDRKPJFv+kquk2XReKwBOCBq8dCSABipaMdH7yCiKm+GfsNrw8rokNfFHUB5u+ORCDMFDWY0G9500ZktMJzOXVw4X0r X-Gm-Message-State: AOJu0YyAxOtzL+zfn0+AHjl+Fq/0swkX2bjPCxogDU7TXJ+B9ykf3Cxf Zz6clnT0icZSPwlUdByJ6OgeKr8j4hxyoqAGfGRjlf4LYusHDNm3 X-Google-Smtp-Source: AGHT+IHYMwjZlv19+SaKgWXyWJsRQom5VvXmsDcanz2W4fQaufh2Ad11g/nT7GY2J2UykR7ESs1R/w== X-Received: by 2002:a05:6602:26d5:b0:817:3d49:5255 with SMTP id ca18e2360f4ac-8173d495300mr332865839f.2.1721251932426; Wed, 17 Jul 2024 14:32:12 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-816c34e5d77sm89721139f.47.2024.07.17.14.32.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 14:32:12 -0700 (PDT) Date: Wed, 17 Jul 2024 16:32:10 -0500 From: Nathan Bossart To: Daniel Gustafsson Cc: Robert Haas , Jeff Davis , PostgreSQL Hackers Subject: Re: optimizing pg_upgrade's once-in-each-database steps Message-ID: References: <20240516211638.GA1688936@nathanxps13> <3b97ab8e295ec3db22baa2dfdd49073449ae1696.camel@j-davis.com> <20240517012408.GA1691322@nathanxps13> <26742670-9539-4F30-B6FA-9C1DB743BC23@yesql.se> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <26742670-9539-4F30-B6FA-9C1DB743BC23@yesql.se> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Jul 17, 2024 at 11:16:59PM +0200, Daniel Gustafsson wrote: > First reaction after a read-through is that this seems really cool, can't wait > to see how much v18 pg_upgrade will be over v17. I will do more testing and > review once back from vacation, below are some comments from reading which is > all I had time for at this point: Thanks for taking a look! > +static void > +conn_failure(PGconn *conn) > +{ > + pg_log(PG_REPORT, "%s", PQerrorMessage(conn)); > + printf(_("Failure, exiting\n")); > + exit(1); > +} > > Any particular reason this isn't using pg_fatal()? IIRC this was to match the error in connectToServer(). We could probably move to pg_fatal(). > +static void > +dispatch_query(const ClusterInfo *cluster, AsyncSlot *slot, > .... > + pg_free(query); > +} > > A minor point, perhaps fueled by me not having played around much with this > patchset. It seems a bit odd that dispatch_query is responsible for freeing > the query from the get_query callback. I would have expected the output from > AsyncTaskGetQueryCB to be stored in AsyncTask and released by async_task_free. I don't see any problem with doing it the way you suggest. Tangentially related, I waffled a bit on whether to require the query callbacks to put the result in allocated memory. Some queries are the same no matter what, and some require customization at runtime. As you can see, I ended up just requiring allocated memory. That makes the code a tad simpler, and I doubt the extra work is noticeable. > +static void > +sub_process(DbInfo *dbinfo, PGresult *res, void *arg) > +{ > .... > + fprintf(state->script, "The table sync state \"%s\" is not allowed for database:\"%s\" subscription:\"%s\" schema:\"%s\" relation:\"%s\"\n", > + PQgetvalue(res, i, 0), > + dbinfo->db_name, > + PQgetvalue(res, i, 1), > > With the query being in a separate place in the code from the processing it > takes a bit of jumping around to resolve the columns in PQgetvalue calls like > this. Using PQfnumber() calls and descriptive names would make this easier. I > know this case is copying old behavior, but the function splits make it less > useful than before. Good point. > + char *query = pg_malloc(QUERY_ALLOC); > > Should we convert this to a PQExpBuffer? Seems like a good idea. I think I was trying to change as few lines as possible for my proof-of-concept. :) -- nathan