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 1tpqZd-00D8Z4-62 for pgsql-general@arkaria.postgresql.org; Wed, 05 Mar 2025 15:22:17 +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 1tpqZb-00DqqM-QO for pgsql-general@arkaria.postgresql.org; Wed, 05 Mar 2025 15:22:15 +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 1tpqZb-00DqqD-BI for pgsql-general@lists.postgresql.org; Wed, 05 Mar 2025 15:22:15 +0000 Received: from mail-il1-x135.google.com ([2607:f8b0:4864:20::135]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tpqZZ-0017rk-0v for pgsql-general@lists.postgresql.org; Wed, 05 Mar 2025 15:22:14 +0000 Received: by mail-il1-x135.google.com with SMTP id e9e14a558f8ab-3d19e40a891so23723265ab.3 for ; Wed, 05 Mar 2025 07:22:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741188132; x=1741792932; 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=7hx/n2BPMP8+snaTTWuWKpr3z0QadVBUOM+s8RGnYTw=; b=isPDpYSY5cluNLgKAhyr56aQ792XzWSzYlheRiHAtk2xS/tFs+CL8BKM+KD5fNlZpG DDS4hXvpTojNiBQwcowUIMkc8P6wMpUBA0QtRevLQQUCXWgF7//2GET9FW0X1yL7HZWh +ao6LT9++fVCr/vOoX4jXzyKNnSYud/fR9iWuA6e52N79zE5SxluNpSOwzt2Sg7algFt RT1lX6CLJvZti6S/DOZwPH9Bca8s7RuCmb1P1w+eldBpiJMIWwRqa7BJSfP7dPyCXg9Y 7+amMlSehjozk+kpunijUJi6+xkl0UgYHPGbdlGJaY8iJm9+nmXrH5BW9XREIK6xqAPV GAnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741188132; x=1741792932; 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=7hx/n2BPMP8+snaTTWuWKpr3z0QadVBUOM+s8RGnYTw=; b=IGAcC8BQViK0bf2/NlRGv+HCy2rBhgpJbm2S2RruhEd6yawQwTuJiZDel95JZ5rDKs CyCeUcxSatpiQFumW4TlPhml9aKqFv+pkMnD0Rb9Xi8zRxUOw0wB/RY4kg41s3lt4Lxb 4sADtK0EGM/7VSWESHcTWCPLxiIos750+qijFAuauYVhujBqQYQo+HmF+u3mWaMYewb+ GsCp8BAfKMqWbYUDacbm/+sraU594xYYjbDA48iuDPH6MSHZ2RQxaPTyJJqgOAyvi0NV vpwCDBgvbG8ZCGCtK8T/fdN/46cNPfF+gn/TOJQcu1YPKYw0C+Zr/zga5JwXOyVLuZJw jpwg== X-Forwarded-Encrypted: i=1; AJvYcCUXsaLLIFOUM8Xccxm3e4RjyNo+zCuA8Famz5hLnz6yQ6CJx9Gmhx/vDHLDUr+rNRVWEdRo6LVxPAS+hKsf@lists.postgresql.org X-Gm-Message-State: AOJu0YwrkGwpI13zPaippEx7WIyFWgJwyEPlPqQej5+DK/a6cuYNy1oR gTlWo6OQhT0FMKcTAZYmyyhurBnqN8F6iMzh6ZArx9pf/pth+VLfo7q6UFUDlhHMjVU+PuhoHoB 5jNTWDz0NFDymzELeWbre38FnOnA= X-Gm-Gg: ASbGncsd2F8sONMz2eEX3jdfEhunkwjXc2SkEtud2XeVv4gODTYO8B6gvq1zKijUoaU t9pme23dd5zflkhjQZQ7CGvdqLMVU49/NdURZK5TJpnq3tkL038DDiVSgmQ85po/NFfVbDKzz29 cBLT/IxFIHShvFkjjVRjEb9Lh7H/yVzHNi0K2gF7gSU559RC5FFrScQMerM1M= X-Google-Smtp-Source: AGHT+IEDiAXL3qOHWhKvfSKigK20uW36x0xDnYF6W4W+F5wqKPHDicQ7ABbBjpJE6Lg2jYv7/gQ5+0ThrkEkS9pg1Ss= X-Received: by 2002:a92:c266:0:b0:3cf:bac5:d90c with SMTP id e9e14a558f8ab-3d42b9759f5mr49187425ab.18.1741188123931; Wed, 05 Mar 2025 07:22:03 -0800 (PST) MIME-Version: 1.0 References: <099b49ebae94e23f19afdad3f8c9c6e702a3a2d5.camel@cybertec.at> In-Reply-To: From: Greg Sabino Mullane Date: Wed, 5 Mar 2025 10:21:27 -0500 X-Gm-Features: AQ5f1JqLTdy-sMb5qnfYmh5tPu1kmGkDZk3v8r-CUVBvhyX3PiY5-cCRs2fWQLQ Message-ID: Subject: Re: Quesion about querying distributed databases To: me nefcanto Cc: Laurenz Albe , Adrian Klaver , pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000009d7379062f99f3c1" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000009d7379062f99f3c1 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Mar 5, 2025 at 7:15=E2=80=AFAM me nefcanto wrot= e: > I think if we put all databases into one database, then we have blocked > our growth in the future. > I think this is premature optimization. Your products table has 100,000 rows. That's very tiny for the year 2025. Try putting everything on one box with good indexes and you might be surprised at the performance. > A monolith database can be scaled only vertically. > Postgres scales well vertically. Plus, you can have streaming replicas to distribute the read queries (like the one given here) across many machines. > We have had huge headaches in the past with SQL Server on Windows and a > single database. > But when you divide bounded contexts into different databases, then you > have the chance to deploy each database on a separate physical machine. > That means a lot in terms of performance. > I get your concern, but if the data is inter-related, it really is best to have them on the same server (and same database, and same schema). Then Postgres can devise a really efficient plan. You can also use Citus to start sharding things across multiple physical servers if your database gets very large. Let's put this physical restriction on ourselves that we have different > databases. What options do we have? > Your main option is FDW, which will never perform as well as a single server. Plus, you have the additional headache of trying to coordinate data updates atomically across different servers. The other option is to have the application do the work, e.g. pull a list of things from one server, use that to build a query against another one, etc. Definitely not ideal. Cheers, Greg -- Crunchy Data - https://www.crunchydata.com Enterprise Postgres Software Products & Tech Support --0000000000009d7379062f99f3c1 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Wed, Mar 5, 2025 at 7:15=E2=80=AFAM me= nefcanto <sn.1361@gmail.com>= ; wrote:
I think if we put all databases into one database,= then we have blocked our growth in the future.

I think= this is premature optimization. Your products table has 100,000 rows. That= 's very tiny for the year 2025. Try putting everything on one box with = good indexes and you might be surprised at the performance.
=C2= =A0
A monolith database can be sc= aled only vertically.

Postgres = scales well vertically. Plus, you can have streaming replicas to distribute= the read queries (like the one given here) across many machines.
=C2=A0
We have had huge headache= s in the past with SQL Server on Windows and a single database.
But when you divide bounded contexts= into different databases, then you have the chance to deploy each database= on a separate physical machine. That means a lot in terms of performance.<= /div>

I get your concern, but if the = data is inter-related, it really is best to have them on the same server (a= nd same database, and same schema). Then Postgres can devise a really effic= ient plan. You can also use Citus to start sharding things across multiple = physical=C2=A0servers if your database gets very large.

Let's put this physical restricti= on on ourselves that we have different databases. What options do we have?<= /div>

Your main option is FDW, which = will never perform as well as a single server. Plus, you have the additiona= l headache of trying to coordinate data updates atomically across different= servers. The other option is to have the application do the work, e.g. pul= l a list of things from one server, use that to build a query against anoth= er one, etc. Definitely not ideal.

Cheers,
Greg

--
Enterprise Postgres Software Products & Tech Support

--0000000000009d7379062f99f3c1--