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 1uDJVh-0096ca-G2 for pgsql-hackers@arkaria.postgresql.org; Fri, 09 May 2025 08:55:15 +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 1uDJVg-009hET-IR for pgsql-hackers@arkaria.postgresql.org; Fri, 09 May 2025 08:55:12 +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 1uDJSQ-009cEh-9q for pgsql-hackers@lists.postgresql.org; Fri, 09 May 2025 08:51:51 +0000 Received: from mail.clear-code.com ([153.126.203.179]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uDJSD-000vQe-2f for pgsql-hackers@postgresql.org; Fri, 09 May 2025 08:51:48 +0000 Received: from localhost (unknown [IPv6:2404:7a80:9f01:f500:1788:74de:dc85:ea72]) by mail.clear-code.com (Postfix) with ESMTPSA id A9040DEF5B; Fri, 9 May 2025 17:51:29 +0900 (JST) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.clear-code.com A9040DEF5B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=clear-code.com; s=default; t=1746780689; bh=Z8kYfDNFKYAookmoJJMZZPaG+INQ54qraTHkh/n8Z7E=; h=Date:To:Cc:Subject:From:In-Reply-To:References:From; b=jZHBZ9NJryvp69eaUDp5EWi4kWv3Y5rX95I7gpkcrzokAte22auz+Ygm7p3Ypwphc Pfusy0vW/q8dPsSmfpAGMf2RzoI8icY9bL5Hlp9Z6rjjH91dnDVE+T/73tjhRicHcq xtsJ73KXkw/05YX3miMec6C/zcHNGHz4ZfiEJpO4= Date: Fri, 09 May 2025 17:51:27 +0900 (JST) Message-Id: <20250509.175127.1022585938948163304.kou@clear-code.com> To: sawada.mshk@gmail.com Cc: david.g.johnston@gmail.com, tgl@sss.pgh.pa.us, zhjwpku@gmail.com, michael@paquier.xyz, pgsql-hackers@postgresql.org Subject: Re: Make COPY format extendable: Extract COPY TO format implementations From: Sutou Kouhei In-Reply-To: References: <20250503.152046.733471828898631796.kou@clear-code.com> X-Mailer: Mew version 6.8 on Emacs 30.1 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Rspamd-Server: mail.clear-code.com X-Rspamd-Queue-Id: A9040DEF5B X-Rspamd-Action: no action X-Spamd-Result: default: False [2.90 / 999.00]; SUSPICIOUS_RECIPS(1.50)[]; MID_CONTAINS_FROM(1.00)[]; MV_CASE(0.50)[]; MIME_GOOD(-0.10)[text/plain]; TAGGED_RCPT(0.00)[]; ARC_NA(0.00)[]; ASN(0.00)[asn:2518, ipnet:2404:7a80::/29, country:JP]; RCVD_COUNT_ZERO(0.00)[0]; MIME_TRACE(0.00)[0:+]; FREEMAIL_TO(0.00)[gmail.com]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; FREEMAIL_CC(0.00)[gmail.com,sss.pgh.pa.us,paquier.xyz,postgresql.org]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_NONE(0.00)[]; RCPT_COUNT_FIVE(0.00)[6] List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, In "Re: Make COPY format extendable: Extract COPY TO format implementations" on Fri, 2 May 2025 23:37:46 -0700, Masahiko Sawada wrote: > The progress information is stored in PgBackendStatus defined in > backend_status.h: > > /* > * Command progress reporting. Any command which wishes can advertise > * that it is running by setting st_progress_command, > * st_progress_command_target, and st_progress_param[]. > * st_progress_command_target should be the OID of the relation which the > * command targets (we assume there's just one, as this is meant for > * utility commands), but the meaning of each element in the > * st_progress_param array is command-specific. > */ > ProgressCommandType st_progress_command; > Oid st_progress_command_target; > int64 st_progress_param[PGSTAT_NUM_PROGRESS_PARAM]; > > Then the progress view maps the numbers to the corresponding strings: > > CREATE VIEW pg_stat_progress_copy AS > SELECT > S.pid AS pid, S.datid AS datid, D.datname AS datname, > S.relid AS relid, > CASE S.param5 WHEN 1 THEN 'COPY FROM' > WHEN 2 THEN 'COPY TO' > END AS command, > CASE S.param6 WHEN 1 THEN 'FILE' > WHEN 2 THEN 'PROGRAM' > WHEN 3 THEN 'PIPE' > WHEN 4 THEN 'CALLBACK' > END AS "type", > S.param1 AS bytes_processed, > S.param2 AS bytes_total, > S.param3 AS tuples_processed, > S.param4 AS tuples_excluded, > S.param7 AS tuples_skipped > FROM pg_stat_get_progress_info('COPY') AS S > LEFT JOIN pg_database D ON S.datid = D.oid; Thanks. I didn't know about how to implement pg_stat_progress_copy. > So the idea is that the backend process sets the format ID somewhere > in st_progress_param, and then the progress view calls a SQL function, > say pg_stat_get_copy_format_name(), with the format ID that returns > the corresponding format name. Does it work when we use session_preload_libraries or the LOAD command? If we have 2 sessions and both of them load "jsonlines" COPY FORMAT extensions, what will be happened? For example: 1. Session 1: Register "jsonlines" 2. Session 2: Register "jsonlines" (Should global format ID <-> format name mapping be updated?) 3. Session 2: Close this session. Unregister "jsonlines". (Can we unregister COPY FORMAT extension?) (Should global format ID <-> format name mapping be updated?) 4. Session 1: Close this session. Unregister "jsonlines". (Can we unregister COPY FORMAT extension?) (Should global format ID <-> format name mapping be updated?) Thanks, -- kou