Skip to content

Commit b4bc847

Browse files
Merge pull request #2287 from oracle-devrel/open_source_data_bpx
pgbouncer + developer coaching OSAK
2 parents f2518d9 + 8e894c2 commit b4bc847

9 files changed

Lines changed: 155 additions & 0 deletions

File tree

data-platform/open-source-data-platforms/oci-opensearch/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ A notebook describing and performing all steps to create and store a custom embe
2020
- [LiveLabs: Search and visualize data with OCI Search Service with OpenSearch](https://apexapps.oracle.com/pls/apex/f?p=133:180:6071760449919::::wid:3427)
2121
- [How to Interact with OpenSearch?](https://www.linkedin.com/pulse/how-interact-opensearch-isma%C3%ABl-hassane-j7z9f/?trackingId=TbuchZqCSDa9X65sWhx8xw%3D%3D)
2222
- [Architecting with OpenSearch](https://www.linkedin.com/pulse/architecting-opensearch-isma%C3%ABl-hassane-gz1jf/?trackingId=xw1G1Yq9SMutkogC3FIJmg%3D%3D)
23+
- [Developer Coaching - Building Real-Time Streams with OCI Streaming with Apache Kafka](https://www.youtube.com/watch?v=AUiuGH05MPE)
2324

2425
# Useful Links
2526

data-platform/open-source-data-platforms/oci-postgresql/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ When you are looking to establish an OCI PostgreSQL instance, connect to it, and
4343
- [GitLab & Standalone Managed PostgreSQL on OCI](https://github.com/andreumdorokhinum/oci_pg_with_gitlab)
4444
- [Use CRON as scheduler for OCI PostgreSQL](https://github.com/andreumdorokhinum/oci_pg_with_unix_cron)
4545
- [Integrate Geoserver and PostGIS using OCI Database with PostgreSQL](https://github.com/oracle-devrel/technology-engineering/tree/main/data-platform/open-source-data-platforms/oci-postgresql/code-examples/postgis-geoserver)
46+
- [Set up PgBouncer for Connection Pooling with OCI Database with PostgreSQL](https://github.com/oracle-devrel/technology-engineering/tree/main/data-platform/open-source-data-platforms/oci-postgresql/code-examples/pgbouncer-setup)
4647

4748
# License
4849

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Copyright (c) 2025 Oracle and/or its affiliates.
2+
3+
The Universal Permissive License (UPL), Version 1.0
4+
5+
Subject to the condition set forth below, permission is hereby granted to any
6+
person obtaining a copy of this software, associated documentation and/or data
7+
(collectively the "Software"), free of charge and under any and all copyright
8+
rights in the Software, and any and all patent rights owned or freely
9+
licensable by each licensor hereunder covering either (i) the unmodified
10+
Software as contributed to or provided by such licensor, or (ii) the Larger
11+
Works (as defined below), to deal in both
12+
13+
(a) the Software, and
14+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
15+
one is included with the Software (each a "Larger Work" to which the Software
16+
is contributed by such licensors),
17+
18+
without restriction, including without limitation the rights to copy, create
19+
derivative works of, display, perform, and distribute the Software and make,
20+
use, sell, offer for sale, import, export, have made, and have sold the
21+
Software and the Larger Work(s), and to sublicense the foregoing rights on
22+
either these or other terms.
23+
24+
This license is subject to the following condition:
25+
The above copyright notice and either this complete permission notice or at
26+
a minimum a reference to the UPL must be included in all copies or
27+
substantial portions of the Software.
28+
29+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35+
SOFTWARE.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Set up PgBouncer for Connection Pooling with OCI Database with PostgreSQL
2+
3+
Reviewed: 25.11.2025
4+
5+
# When to use this asset?
6+
7+
Developers aiming to use PgBouncer for connection pooling.
8+
9+
# How to use this asset?
10+
11+
Open the pgbouncer-setup.md file and follow the steps carefully.
12+
13+
# Pre-requisites:
14+
15+
- Create a VCN with public and private subnet
16+
- Create an OCI PostgreSQL database instance in the private subnet
17+
- Create a Ubuntu instance in public subnet, same VCN
18+
- Add ports 5432, 6543 to the private subnet security list
19+
20+
# License
21+
22+
Copyright (c) 2025 Oracle and/or its affiliates.
23+
24+
Licensed under the Universal Permissive License (UPL), Version 1.0.
25+
26+
See [LICENSE](https://github.com/oracle-devrel/technology-engineering/blob/main/LICENSE) for more details.
48.9 KB
Loading
244 KB
Loading
52.6 KB
Loading
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Set up PgBouncer for Connection Pooling with OCI Database with PostgreSQL
2+
3+
Often, clients would like to add connection pooling to their OCI Database with PostgreSQL.
4+
The following steps are an example to set up connection pooling, using [PgBouncer](https://www.pgbouncer.org/).
5+
6+
The set up is similar to below simplified architecture. Connections are passed through a Network Load Balancer, with the pg_bouncer instances as backend set.
7+
Following, the pg_bouncer - as the connection pooler - connect to multiple PostgreSQL databases or the invidual nodes, to differentiate between read/write and read-only.
8+
9+
![image](images/img_0.png)
10+
11+
# 1. Set up OCI Database with PostgreSQL
12+
Follow [these steps to set up one or more OCI Database with PostgreSQL deployments](https://docs.oracle.com/en-us/iaas/Content/postgresql/getting-started.htm#database)
13+
14+
- After creating the databases, review the max_connections you have in the database.
15+
- Make sure to open ports (5432) in your public/private subnet
16+
17+
# 2. Set up Network Load Balancer
18+
Follow [these steps to set up a NLB on OCI](https://docs.oracle.com/en-us/iaas/Content/NetworkLoadBalancer/NetworkLoadBalancers/network-load-balancer-management.htm).
19+
For the back end set, you will need to add the OCI Compute instances running pg_bouncer.
20+
21+
# 3. Set up multiple OCI Compute instances to run pg_bouncer
22+
23+
The below example uses Canonical Ubuntu 24.04 and assumes your PostgreSQL database is version 14.
24+
25+
- Install pg_bouncer on the compute.
26+
```
27+
sudo apt-get install pgbouncer
28+
```
29+
30+
- Configure the user list. These are the admin credentials.
31+
```
32+
sudo vim etc/pgbouncer/userlist.txt
33+
```
34+
35+
- Add your username and password of your OCI Database with PostgreSQL instances.
36+
```
37+
"Example_user" "example_password"
38+
```
39+
40+
- Change the pg_bouncer config file. These determine the connection details to the database, the auth type, session type, etc.
41+
```
42+
sudo vim etc/pgbouncer/pgbouncer.ini
43+
```
44+
45+
- Change the [database] section to the below. The hosts and dbname are examples.
46+
```
47+
[databases]
48+
49+
writer = host=[YOUR_PRIMARY_ENDPOINT] port=5432 dbname=postgres
50+
reader = host=[YOUR_READER_ENDPOINT] port=5432 dbname=postgres
51+
```
52+
53+
- Change the list_addr to *
54+
```
55+
listen_addr = *
56+
```
57+
58+
- Uncomment the below. Change the client connections and pool size to your needs.
59+
```
60+
pool_mode = session
61+
server_reset_query = DISCARD ALL
62+
max_client_conn = 100
63+
default_pool_size = 20
64+
```
65+
66+
Save and close the file. An example of config file.
67+
68+
![image](images/img_3.png)
69+
70+
- Restart pg_bouncer and review status
71+
```
72+
sudo systemctl restart pgbouncer.service
73+
systemctl status pgbouncer.service
74+
````
75+
76+
![image](images/img_4.png)
77+
78+
# 4 Review PgBouncer connection
79+
80+
- Install PostgreSQL client if not done
81+
```
82+
sudo apt-get install postgresql postgresql-client
83+
```
84+
85+
- Connect using psql, through pg_bouncer. Add your password when prompted.
86+
```
87+
psql -h localhost -p 6432 -U pgadmin -d writer
88+
```
89+
90+
When working, you should see Writer =>.
91+

data-platform/open-source-data-platforms/oci-streaming-with-apache-kafka/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Reviewed: 11.11.2025
1010
3. [Reusable Assets](#reusable-assets)
1111

1212
# Team Publications
13+
- [Developer Coaching - Building Real-Time Streams with OCI Streaming with Apache Kafka](https://www.youtube.com/watch?v=AUiuGH05MPE)
1314

1415
# Useful Links
1516

0 commit comments

Comments
 (0)