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 1tesDK-00G8bJ-QD for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Feb 2025 08:53:55 +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 1tesDJ-00Bc6G-QV for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Feb 2025 08:53:53 +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 1tesDJ-00Bc67-DG for pgsql-hackers@lists.postgresql.org; Mon, 03 Feb 2025 08:53:53 +0000 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tesDH-002uzi-0e for pgsql-hackers@lists.postgresql.org; Mon, 03 Feb 2025 08:53:52 +0000 Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-aaec111762bso289585466b.2 for ; Mon, 03 Feb 2025 00:53:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738572830; x=1739177630; 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=1nv9Vl+7huStwgb7TBkMP5QSmgJ4lHgZ2IqmfN7QKfU=; b=IPsvLbyAt9lCORr2pfkBKFmam2nQ+flIWC3an3Ap5J5EL/1q//EKrtgbbKizWlKEJb zh8vKGVdrWWuH+FkR/WMuSY/jdCOn8E1mKW6oBJBL5yc+gz6QaNKthjVAXOw1A0v5Jyi JFGDzpuqHV7AvnYtD+sL0zYkKBEU1n6ocKJ3n3A7kG1I+36OYIfxxTU0/hG/lSIg2z7A ei/hNiGVA8QRqKOTyAujiDyB8vZuathxzGOvh5kIDYryZVORoq56XFlh0LK3qel5/fMr XxAlubRsHA1WCWtH7u8vLHNfuDD2zp4x4CmEL/KYYAlvoXYVVKLGOPJIpJ2R2KlLUEhr RgxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738572830; x=1739177630; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1nv9Vl+7huStwgb7TBkMP5QSmgJ4lHgZ2IqmfN7QKfU=; b=HNm56bGrvHwz8cs2hMZVFHNviAQXdcONkSAjTYUsCB33wG3bePT0CPvjVewLBLKfNf yEQO1oVa2CsWx7p6Gt+ZsGkF6iQBI+jHoCavOofHwz16TcLBjZme9raAcz3HjKWFWqkY /ZEhIAurSsj9TMAN/Xpic/twlbHXAgplD0BnKDXgjWH7Yx85KvqgONWgCwPqyueoQlag 86bAHcqjHhNxE3fCTZP69ZcasmUyNI+xLf2WRty39YQ25JquqHC1vrfFmYc2d0xwzF2Z I7EjrjsTah2nVqv572u/2T2x3wGFnPDiS/E2OtPVpm/6WtD+pjAYuOF4j7Nk/3cgVY5T nhow== X-Gm-Message-State: AOJu0Yye3KOnYGcpq1t5p7sebYa4WcKXmSDOS3+mHvAVQbQKD2XuRgZ1 1CsgzL3TGZzyrEv4oo1KVGiy+d+feOwlLsJHWuhll2vZXaJ85vffy67s7UGVDzRyOgBIKYxqBvk uH8UAQBNBYw7bJBFk0aXD97awjOO4hqc0baA= X-Gm-Gg: ASbGncsd04XfPX+SzPeaEPuUgZBpXB/y+QZz59oubig0MzpxoMgqRiqS1eukw4XYLAQ sGWrRDcRZP3G1gMRtSYsxEbD2C7Mpjkz/Nc3WH+T4ebjHEpuutO9DRM3tWe/OPjAIxUuBUUkcwg == X-Google-Smtp-Source: AGHT+IEGOzzTzcvSSu0mvfykmiadqu4W9OTu7UUAKSia0NeCFlzumfK96wRwBCYsfAbYIQyXnz/RicjM2sJ8mG1TfO8= X-Received: by 2002:a17:907:1c95:b0:ab7:992:7f42 with SMTP id a640c23a62f3a-ab709927f70mr1063822866b.34.1738572829652; Mon, 03 Feb 2025 00:53:49 -0800 (PST) MIME-Version: 1.0 References: <202501110844.5ztsym4vbflm@alvherre.pgsql> In-Reply-To: From: Srinath Reddy Date: Mon, 3 Feb 2025 14:23:38 +0530 X-Gm-Features: AWEUYZkk7zakne0TnqAkR8hfEyuf-uCxHeYDpurCetqIadqFZzOWGMNVdKCAw-M Message-ID: Subject: Re: Non-text mode for pg_dumpall To: Mahendra Singh Thalor , jian.universality@gmail.com Cc: pgsql-hackers@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000ed8068062d39073c" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000ed8068062d39073c Content-Type: text/plain; charset="UTF-8" Hi, I found a bug ,while using "./pg_restore pdd -f -" actually it has to copy everything(global sql commands + remaining dump ) into stdout as per the "-f, --file=FILENAME output file name (- for stdout)" but it is copying global sql commands to a file literally naming it as "-" and remaining dump is written to stdout without those global sql commands."-" is not a output file it signifies stdout in terminal cmds.so we have to handle this case. because of above reason "./pg_restore pdd -g -f -" also does the same creates a file "-" and writes globals to that file instead of stdout. This is the delta patch to handle this case.please have a look and give some feedback. @@ -84,7 +84,7 @@ static int restoreAllDatabases(PGconn *conn, const char *dumpdirpath, SimpleStringList db_exclude_patterns, RestoreOptions *opts, int numWorkers); static void execute_global_sql_commands(PGconn *conn, const char *dumpdirpath, const char *outfile); -static void copy_global_file_to_out_file(const char *outfile, FILE *pfile); +static void copy_global_file(const char *outfile, FILE *pfile); static int filter_dbnames_for_restore(PGconn *conn, SimpleDatabaseOidList *dbname_oid_list, - ofile = fopen(out_file_path, PG_BINARY_W); + if (strcmp(outfile, "-") == 0){ + int fn = fileno(stdout); + ofile = fdopen(dup(fn), PG_BINARY_W); + } + else{ + snprintf(out_file_path, MAXPGPATH, "%s", outfile); + ofile = fopen(out_file_path, PG_BINARY_W); + } + if (ofile == NULL) { Regards, Srinath Reddy Sadipiralla, EDB: https://www.enterprisedb.com > --000000000000ed8068062d39073c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,
I found=C2=A0a bug ,while using "./pg_res= tore pdd -f -" actually it has to copy everything(global sql commands = + remaining dump )=C2=A0into stdout as per the "-f, --file=3DFILENAME = =C2=A0 =C2=A0 =C2=A0output file name (- for stdout)" but it is copying= global sql commands to a file literally naming it as "-" and rem= aining dump is written to stdout without those global sql commands."-&= quot; is not a output file it signifies stdout in terminal cmds.so we have = to handle this case.
because of above reason "./pg_restore pdd -g -= f -"=C2=A0 also=C2=A0=C2=A0does the same creates a file "-" = and writes globals to that file instead of stdout.

This is the delta= patch to handle this case.please have a look and give some feedback.
@@ -84,7 +84,7 @@ static int restoreAllDatabases(PGconn *conn, const char= *dumpdirpath,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0SimpleStringList db_exclude_patterns, RestoreOptions *opts, int numWo= rkers);
=C2=A0static void execute_global_sql_commands(PGconn *conn, cons= t char *dumpdirpath,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 const char *outfile);
-static void copy_global_file_to_out_fi= le(const char *outfile, FILE *pfile);
+static void copy_global_file(cons= t char *outfile, FILE *pfile);
=C2=A0static int filter_dbnames_for_resto= re(PGconn *conn,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 SimpleDatabaseOidLi= st *dbname_oid_list,
- =C2=A0 =C2=A0 =C2=A0 ofile =3D fopen(out_file_pat= h, PG_BINARY_W);
+ =C2=A0 =C2=A0 =C2=A0 if (strcmp(outfile, "-"= ;) =3D=3D 0){
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 int =C2= =A0 =C2=A0 fn =3D fileno(stdout);
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 ofile =3D fdopen(dup(fn), PG_BINARY_W);
+ =C2=A0 =C2=A0 = =C2=A0 }
+ =C2=A0 =C2=A0 =C2=A0 else{
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 snprintf(out_file_path, MAXPGPATH, "%s", out= file);
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ofile =3D fope= n(out_file_path, PG_BINARY_W);
+ =C2=A0 =C2=A0 =C2=A0 }
+
=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (ofile =3D=3D NULL)
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 {

Regards,
Srinath Reddy Sadipiralla,
EDB:=C2=A0https://www.enterprisedb.com<= /div>
--000000000000ed8068062d39073c--