跳到主要内容

3 篇博文 含有标签「postgresql」

查看所有标签

财经今日 开源了:界面、它读的库表结构,以及中间的 API

· 阅读需 8 分钟
财经今日 · CaiJing Today财经今日 · CaiJing Today

一个交易日,是六个标签页​

九点二十五,集合竞价结束。九点半,开盘。从这一刻起,接下来四个小时, 市场一直在说话:一次公开市场操作、一个期货点位、一个指数点位、一份征求意见 稿、一份公司公告,再加上一篇分析——而这两者到底差在哪。

这些消息都是真的,也都真实存在。只是它们不在同一个地方。

于是你打开六个标签页:行情快讯、指数页面、板块热力图、日历、公告检索、还有 一个论坛。它们各自的版式、配色、关注点都不一样,而且大多是为别人的问题而 做的。

CaiJing Today is open source — the board, the schema it reads, and the API in between

· 阅读需 9 分钟
CaiJing Today · 财经今日CaiJing Today · 财经今日

A market day is a lot of tabs​

At 09:25 the call auction ends. At 09:30 the tape starts, and for the next four hours the Chinese market talks continuously — a central-bank operation, a futures point, an index level, a draft regulation, a company filing, an analyst note about the difference between two of them.

All of it is real, and all of it is somewhere. But it is not in the same place.

So you end up with six tabs open — a wire service, a quote page, a sector heatmap, a calendar, a filing index, a forum — and the tab bar quietly becomes the product. Every one of them is a different layout, a different colour scheme, a different idea of what matters, and most of them are built for somebody else's question.

Best Practices of Deploying PostgreSQL in Kubernetes

· 阅读需 3 分钟

This guide walks through deploying PostgreSQL in a Kubernetes Pod with a sidecar container that collects PostgreSQL logs and forwards them to Elasticsearch. We’ll use Helm to manage deployments, including setting up necessary ConfigMaps and Secrets for configuration.

Project Structure​

postgresql-logging/
├── charts/
│ └── postgresql-log-sidecar/
│ ├── Chart.yaml
│ ├── templates/
│ │ ├── configmap.yaml
│ │ ├── deployment.yaml
│ │ ├── secret.yaml
│ │ ├── service.yaml
│ ├── values.yaml
├── README.md

1. Architecture Overview​

The following diagram shows how the PostgreSQL Pod and the sidecar interact for log collection:

+-----------------------------------+
| PostgreSQL Pod |
| |
| +-----------------------------+ |
| | PostgreSQL Container | |
| | - Exposes Port 5432 | |
| +-----------------------------+ |
| |
| +-----------------------------+ |
| | Log Collector | |
| | - Collects Logs | |
| | - Pushes to Elasticsearch | |
| +-----------------------------+ |
+-----------------------------------+

2. Helm Chart Configuration​

Chart.yaml​

apiVersion: v2
name: postgresql-log-sidecar
description: A Helm chart for PostgreSQL with log sidecar
version: 0.1.0
appVersion: "13"

values.yaml​

Define values for PostgreSQL configuration and the sidecar container.

postgresql:
username: admin
password: password123
database: appdb

elasticsearch:
host: "elasticsearch:9200"
index: "postgresql-logs"

sidecar:
image: fluent/fluent-bit
tag: "1.8"
resources:
limits:
memory: "200Mi"
requests:
memory: "100Mi"

3. ConfigMap and Secret​

configmap.yaml​

This ConfigMap includes log configuration for the sidecar container.

apiVersion: v1
kind: ConfigMap
metadata:
name: postgresql-log-config
data:
fluent-bit.conf: |
[SERVICE]
Flush 1
Log_Level info

[INPUT]
Name tail
Path /var/log/postgresql/postgresql.log
Tag postgresql

[OUTPUT]
Name es
Match *
Host {{ .Values.elasticsearch.host }}
Port 9200
Index {{ .Values.elasticsearch.index }}

secret.yaml​

Create a Secret for PostgreSQL credentials.

apiVersion: v1
kind: Secret
metadata:
name: postgresql-secret
type: Opaque
data:
postgresql-username: {{ .Values.postgresql.username | b64enc }}
postgresql-password: {{ .Values.postgresql.password | b64enc }}

4. Deployment Configuration​

deployment.yaml​

The main deployment file sets up PostgreSQL and the Fluent Bit sidecar container.

apiVersion: apps/v1
kind: Deployment
metadata:
name: postgresql-log-sidecar
spec:
replicas: 1
selector:
matchLabels:
app: postgresql
template:
metadata:
labels:
app: postgresql
spec:
containers:
- name: postgresql
image: postgres:13
ports:
- containerPort: 5432
env:
- name: POSTGRES_DB
value: {{ .Values.postgresql.database }}
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: postgresql-secret
key: postgresql-username
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: postgresql-secret
key: postgresql-password
volumeMounts:
- name: postgres-logs
mountPath: /var/log/postgresql
resources:
requests:
memory: "500Mi"
limits:
memory: "1Gi"

- name: log-collector
image: {{ .Values.sidecar.image }}:{{ .Values.sidecar.tag }}
args: ["-c", "/fluent-bit/etc/fluent-bit.conf"]
volumeMounts:
- name: postgres-logs
mountPath: /var/log/postgresql
- name: config
mountPath: /fluent-bit/etc
subPath: fluent-bit.conf
resources:
limits:
memory: {{ .Values.sidecar.resources.limits.memory }}
requests:
memory: {{ .Values.sidecar.resources.requests.memory }}
volumes:
- name: postgres-logs
emptyDir: {}
- name: config
configMap:
name: postgresql-log-config

service.yaml​

Create a Service to expose PostgreSQL internally within the cluster.

apiVersion: v1
kind: Service
metadata:
name: postgresql
spec:
type: ClusterIP
ports:
- port: 5432
targetPort: 5432
selector:
app: postgresql

5. Deploying the Helm Chart​

Install the chart with:

helm install postgresql-log-sidecar ./charts/postgresql-log-sidecar