mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-20 11:52:56 +00:00
Compare commits
6 Commits
hackathon/
...
hack/compu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1bf5e07da1 | ||
|
|
87de91b004 | ||
|
|
2f217f9ebd | ||
|
|
71491dd467 | ||
|
|
67e791c4ec | ||
|
|
517782ab94 |
@@ -714,6 +714,23 @@ RUN wget https://github.com/pksunkara/pgx_ulid/archive/refs/tags/v0.1.3.tar.gz -
|
|||||||
cargo pgrx install --release && \
|
cargo pgrx install --release && \
|
||||||
echo "trusted = true" >> /usr/local/pgsql/share/extension/ulid.control
|
echo "trusted = true" >> /usr/local/pgsql/share/extension/ulid.control
|
||||||
|
|
||||||
|
#########################################################################################
|
||||||
|
#
|
||||||
|
# Layer "pg-wait-sampling-pg-build"
|
||||||
|
# compile pg_wait_sampling extension
|
||||||
|
#
|
||||||
|
#########################################################################################
|
||||||
|
FROM build-deps AS pg-wait-sampling-pg-build
|
||||||
|
COPY --from=pg-build /usr/local/pgsql/ /usr/local/pgsql/
|
||||||
|
|
||||||
|
ENV PATH "/usr/local/pgsql/bin/:$PATH"
|
||||||
|
RUN wget https://github.com/postgrespro/pg_wait_sampling/archive/refs/tags/v1.1.5.tar.gz -O pg_wait_sampling.tar.gz && \
|
||||||
|
echo 'a03da6a413f5652ce470a3635ed6ebba528c74cb26aa4cfced8aff8a8441f81ec6dd657ff62cd6ce96a4e6ce02cad9f2519ae9525367ece60497aa20faafde5c pg_wait_sampling.tar.gz' | sha512sum -c && \
|
||||||
|
mkdir pg_wait_sampling-src && cd pg_wait_sampling-src && tar xvzf ../pg_wait_sampling.tar.gz --strip-components=1 -C . && \
|
||||||
|
make USE_PGXS=1 -j $(getconf _NPROCESSORS_ONLN) && \
|
||||||
|
make USE_PGXS=1 -j $(getconf _NPROCESSORS_ONLN) install && \
|
||||||
|
echo 'trusted = true' >> /usr/local/pgsql/share/extension/pg_wait_sampling.control
|
||||||
|
|
||||||
#########################################################################################
|
#########################################################################################
|
||||||
#
|
#
|
||||||
# Layer "neon-pg-ext-build"
|
# Layer "neon-pg-ext-build"
|
||||||
@@ -750,6 +767,7 @@ COPY --from=rdkit-pg-build /usr/local/pgsql/ /usr/local/pgsql/
|
|||||||
COPY --from=pg-uuidv7-pg-build /usr/local/pgsql/ /usr/local/pgsql/
|
COPY --from=pg-uuidv7-pg-build /usr/local/pgsql/ /usr/local/pgsql/
|
||||||
COPY --from=pg-roaringbitmap-pg-build /usr/local/pgsql/ /usr/local/pgsql/
|
COPY --from=pg-roaringbitmap-pg-build /usr/local/pgsql/ /usr/local/pgsql/
|
||||||
COPY --from=pg-embedding-pg-build /usr/local/pgsql/ /usr/local/pgsql/
|
COPY --from=pg-embedding-pg-build /usr/local/pgsql/ /usr/local/pgsql/
|
||||||
|
COPY --from=pg-wait-sampling-pg-build /usr/local/pgsql/ /usr/local/pgsql/
|
||||||
COPY pgxn/ pgxn/
|
COPY pgxn/ pgxn/
|
||||||
|
|
||||||
RUN make -j $(getconf _NPROCESSORS_ONLN) \
|
RUN make -j $(getconf _NPROCESSORS_ONLN) \
|
||||||
|
|||||||
@@ -210,12 +210,7 @@ impl GlobalConnPool {
|
|||||||
client.session.send(session_id)?;
|
client.session.send(session_id)?;
|
||||||
latency_timer.pool_hit();
|
latency_timer.pool_hit();
|
||||||
latency_timer.success();
|
latency_timer.success();
|
||||||
return Ok(Client {
|
return Ok(Client::new(client, pool).await);
|
||||||
conn_id: client.conn_id,
|
|
||||||
inner: Some(client),
|
|
||||||
span: Span::current(),
|
|
||||||
pool,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let conn_id = uuid::Uuid::new_v4();
|
let conn_id = uuid::Uuid::new_v4();
|
||||||
@@ -263,15 +258,11 @@ impl GlobalConnPool {
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
new_client.map(|inner| Client {
|
// new_client.map(|inner| Client::new(inner, pool).await)
|
||||||
conn_id: inner.conn_id,
|
Ok(Client::new(new_client?, pool).await)
|
||||||
inner: Some(inner),
|
|
||||||
span: Span::current(),
|
|
||||||
pool,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn put(&self, conn_info: &ConnInfo, client: ClientInner) -> anyhow::Result<()> {
|
fn put(&self, conn_info: &ConnInfo, client: ClientInner, pid: i32) -> anyhow::Result<()> {
|
||||||
let conn_id = client.conn_id;
|
let conn_id = client.conn_id;
|
||||||
|
|
||||||
// We want to hold this open while we return. This ensures that the pool can't close
|
// We want to hold this open while we return. This ensures that the pool can't close
|
||||||
@@ -315,9 +306,9 @@ impl GlobalConnPool {
|
|||||||
|
|
||||||
// do logging outside of the mutex
|
// do logging outside of the mutex
|
||||||
if returned {
|
if returned {
|
||||||
info!(%conn_id, "pool: returning connection '{conn_info}' back to the pool, total_conns={total_conns}, for this (db, user)={per_db_size}");
|
info!(%conn_id, "pool: returning connection '{conn_info}' back to the pool, total_conns={total_conns}, for this (db, user)={per_db_size}, pid={pid}");
|
||||||
} else {
|
} else {
|
||||||
info!(%conn_id, "pool: throwing away connection '{conn_info}' because pool is full, total_conns={total_conns}");
|
info!(%conn_id, "pool: throwing away connection '{conn_info}' because pool is full, total_conns={total_conns}, pid={pid}");
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -528,6 +519,22 @@ struct ClientInner {
|
|||||||
conn_id: uuid::Uuid,
|
conn_id: uuid::Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ClientInner {
|
||||||
|
pub async fn get_pid(&mut self) -> anyhow::Result<i32> {
|
||||||
|
let rows = self.inner.query("select pg_backend_pid();", &[]).await?;
|
||||||
|
if rows.len() != 1 {
|
||||||
|
Err(anyhow::anyhow!(
|
||||||
|
"expected 1 row from pg_backend_pid(), got {}",
|
||||||
|
rows.len()
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
let pid = rows[0].get(0);
|
||||||
|
info!(%pid, "got pid");
|
||||||
|
Ok(pid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Client {
|
impl Client {
|
||||||
pub fn metrics(&self) -> Arc<MetricCounter> {
|
pub fn metrics(&self) -> Arc<MetricCounter> {
|
||||||
USAGE_METRICS.register(self.inner.as_ref().unwrap().ids.clone())
|
USAGE_METRICS.register(self.inner.as_ref().unwrap().ids.clone())
|
||||||
@@ -539,6 +546,7 @@ pub struct Client {
|
|||||||
span: Span,
|
span: Span,
|
||||||
inner: Option<ClientInner>,
|
inner: Option<ClientInner>,
|
||||||
pool: Option<(ConnInfo, Arc<GlobalConnPool>)>,
|
pool: Option<(ConnInfo, Arc<GlobalConnPool>)>,
|
||||||
|
pid: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Discard<'a> {
|
pub struct Discard<'a> {
|
||||||
@@ -547,12 +555,25 @@ pub struct Discard<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Client {
|
impl Client {
|
||||||
|
pub(self) async fn new(
|
||||||
|
mut inner: ClientInner,
|
||||||
|
pool: Option<(ConnInfo, Arc<GlobalConnPool>)>,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
conn_id: inner.conn_id,
|
||||||
|
pid: inner.get_pid().await.unwrap_or(-1),
|
||||||
|
inner: Some(inner),
|
||||||
|
span: Span::current(),
|
||||||
|
pool,
|
||||||
|
}
|
||||||
|
}
|
||||||
pub fn inner(&mut self) -> (&mut tokio_postgres::Client, Discard<'_>) {
|
pub fn inner(&mut self) -> (&mut tokio_postgres::Client, Discard<'_>) {
|
||||||
let Self {
|
let Self {
|
||||||
inner,
|
inner,
|
||||||
pool,
|
pool,
|
||||||
conn_id,
|
conn_id,
|
||||||
span: _,
|
span: _,
|
||||||
|
pid: _,
|
||||||
} = self;
|
} = self;
|
||||||
(
|
(
|
||||||
&mut inner
|
&mut inner
|
||||||
@@ -609,10 +630,11 @@ impl Drop for Client {
|
|||||||
.expect("client inner should not be removed");
|
.expect("client inner should not be removed");
|
||||||
if let Some((conn_info, conn_pool)) = self.pool.take() {
|
if let Some((conn_info, conn_pool)) = self.pool.take() {
|
||||||
let current_span = self.span.clone();
|
let current_span = self.span.clone();
|
||||||
|
let pid = self.pid;
|
||||||
// return connection to the pool
|
// return connection to the pool
|
||||||
tokio::task::spawn_blocking(move || {
|
tokio::task::spawn_blocking(move || {
|
||||||
let _span = current_span.enter();
|
let _span = current_span.enter();
|
||||||
let _ = conn_pool.put(&conn_info, client);
|
let _ = conn_pool.put(&conn_info, client, pid);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,15 +4,15 @@ commands:
|
|||||||
- name: cgconfigparser
|
- name: cgconfigparser
|
||||||
user: root
|
user: root
|
||||||
sysvInitAction: sysinit
|
sysvInitAction: sysinit
|
||||||
shell: 'cgconfigparser -l /etc/cgconfig.conf -s 1664'
|
shell: "cgconfigparser -l /etc/cgconfig.conf -s 1664"
|
||||||
- name: pgbouncer
|
- name: pgbouncer
|
||||||
user: nobody
|
user: nobody
|
||||||
sysvInitAction: respawn
|
sysvInitAction: respawn
|
||||||
shell: '/usr/local/bin/pgbouncer /etc/pgbouncer.ini'
|
shell: "/usr/local/bin/pgbouncer /etc/pgbouncer.ini"
|
||||||
- name: postgres-exporter
|
- name: postgres-exporter
|
||||||
user: nobody
|
user: nobody
|
||||||
sysvInitAction: respawn
|
sysvInitAction: respawn
|
||||||
shell: 'DATA_SOURCE_NAME="user=cloud_admin sslmode=disable dbname=postgres" /bin/postgres_exporter'
|
shell: 'DATA_SOURCE_NAME="user=cloud_admin sslmode=disable dbname=postgres" /bin/postgres_exporter --extend.query-path /etc/postgres_exporter_queries.yml'
|
||||||
shutdownHook: |
|
shutdownHook: |
|
||||||
su -p postgres --session-command '/usr/local/bin/pg_ctl stop -D /var/db/postgres/compute/pgdata -m fast --wait -t 10'
|
su -p postgres --session-command '/usr/local/bin/pg_ctl stop -D /var/db/postgres/compute/pgdata -m fast --wait -t 10'
|
||||||
files:
|
files:
|
||||||
@@ -46,6 +46,21 @@ files:
|
|||||||
}
|
}
|
||||||
memory {}
|
memory {}
|
||||||
}
|
}
|
||||||
|
- filename: postgres_exporter_queries.yml
|
||||||
|
content: |
|
||||||
|
postgres_exporter_pg_database_size:
|
||||||
|
query: "SELECT pg_database.datname, pg_database_size(pg_database.datname) as bytes, 42 as fourtytwo FROM pg_database"
|
||||||
|
cache_seconds: 30
|
||||||
|
metrics:
|
||||||
|
- datname:
|
||||||
|
usage: "LABEL"
|
||||||
|
description: "Name of the database"
|
||||||
|
- bytes:
|
||||||
|
usage: "GAUGE"
|
||||||
|
description: "Disk space used by the database"
|
||||||
|
- fourtytwo:
|
||||||
|
usage: "GAUGE"
|
||||||
|
description: "fourtytwo"
|
||||||
build: |
|
build: |
|
||||||
# Build cgroup-tools
|
# Build cgroup-tools
|
||||||
#
|
#
|
||||||
@@ -114,10 +129,12 @@ merge: |
|
|||||||
|
|
||||||
COPY cgconfig.conf /etc/cgconfig.conf
|
COPY cgconfig.conf /etc/cgconfig.conf
|
||||||
COPY pgbouncer.ini /etc/pgbouncer.ini
|
COPY pgbouncer.ini /etc/pgbouncer.ini
|
||||||
|
COPY postgres_exporter_queries.yml /etc/postgres_exporter_queries.yml
|
||||||
RUN set -e \
|
RUN set -e \
|
||||||
&& chown postgres:postgres /etc/pgbouncer.ini \
|
&& chown postgres:postgres /etc/pgbouncer.ini \
|
||||||
&& chmod 0644 /etc/pgbouncer.ini \
|
&& chmod 0644 /etc/pgbouncer.ini \
|
||||||
&& chmod 0644 /etc/cgconfig.conf
|
&& chmod 0644 /etc/cgconfig.conf \
|
||||||
|
&& chmod 0644 /etc/postgres_exporter_queries.yml
|
||||||
|
|
||||||
COPY --from=libcgroup-builder /libcgroup-install/bin/* /usr/bin/
|
COPY --from=libcgroup-builder /libcgroup-install/bin/* /usr/bin/
|
||||||
COPY --from=libcgroup-builder /libcgroup-install/lib/* /usr/lib/
|
COPY --from=libcgroup-builder /libcgroup-install/lib/* /usr/lib/
|
||||||
|
|||||||
Reference in New Issue
Block a user