आधिकारिक PostgreSQL डॉकर छवि की कॉन्फ़िगरेशन फ़ाइल को कैसे अनुकूलित करें?


101

मैं अपने विन्यास को अनुकूलित करने की कोशिश कर रहे आधिकारिक पोस्टग्रेज डॉकटर छवि का उपयोग कर रहा हूं । इस उद्देश्य के लिए, मैं उदाहरण के sedलिए बदलने के max_connectionsलिए कमांड का उपयोग करता हूं :

sed -i -e"s/^max_connections = 100.*$/max_connections = 1000/" /var/lib/postgresql/data/postgresql.conf

मैंने इस कॉन्फ़िगरेशन को लागू करने के लिए दो तरीकों की कोशिश की। सबसे पहले एक स्क्रिप्ट में कमांड्स को जोड़ना और इसे इनिट फ़ोल्डर "/docker-entrypoint-initdb.d" के भीतर कॉपी करना है। दूसरी विधि उन्हें सीधे मेरे Dockerfile में "RUN" कमांड के साथ चलाकर होती है (यह विधि गैर-आधिकारिक Postgresql छवि के साथ कॉन्फ़िगरेशन फ़ाइल के लिए एक अलग पथ के साथ ठीक काम करती है "/ etc / postgres / ...")। दोनों मामलों में परिवर्तन विफल हो जाते हैं क्योंकि कॉन्फ़िगरेशन फ़ाइल गायब है (मुझे लगता है कि यह अभी तक नहीं बनाया गया है)।

मुझे कॉन्फ़िगरेशन कैसे बदलना चाहिए?

1 संपादित करें:

यहाँ छवि बनाने के लिए Dockerfile का उपयोग किया गया है:

# Database (http://www.cs3c.ma/)

FROM postgres:9.4
MAINTAINER Sabbane <contact@cs3c.ma>

ENV TERM=xterm

RUN apt-get update
RUN apt-get install -y nano

ADD scripts /scripts
# ADD scripts/setup-my-schema.sh /docker-entrypoint-initdb.d/

# Allow connections from anywhere.
RUN sed -i -e"s/^#listen_addresses =.*$/listen_addresses = '*'/" /var/lib/postgresql/data/postgresql.conf
RUN echo "host    all    all    0.0.0.0/0    md5" >> /var/lib/postgresql/data/pg_hba.conf

# Configure logs
RUN sed -i -e"s/^#logging_collector = off.*$/logging_collector = on/" /var/lib/postgresql/data/postgresql.conf
RUN sed -i -e"s/^#log_directory = 'pg_log'.*$/log_directory = '\/var\/log\/postgresql'/" /var/lib/postgresql/data/postgresql.conf
RUN sed -i -e"s/^#log_filename = 'postgresql-\%Y-\%m-\%d_\%H\%M\%S.log'.*$/log_filename = 'postgresql_\%a.log'/" /var/lib/postgresql/data/postgresql.conf
RUN sed -i -e"s/^#log_file_mode = 0600.*$/log_file_mode = 0644/" /var/lib/postgresql/data/postgresql.conf
RUN sed -i -e"s/^#log_truncate_on_rotation = off.*$/log_truncate_on_rotation = on/" /var/lib/postgresql/data/postgresql.conf
RUN sed -i -e"s/^#log_rotation_age = 1d.*$/log_rotation_age = 1d/" /var/lib/postgresql/data/postgresql.conf
RUN sed -i -e"s/^#log_min_duration_statement = -1.*$/log_min_duration_statement = 0/" /var/lib/postgresql/data/postgresql.conf
RUN sed -i -e"s/^#log_checkpoints = off.*$/log_checkpoints = on/" /var/lib/postgresql/data/postgresql.conf
RUN sed -i -e"s/^#log_connections = off.*$/log_connections = on/" /var/lib/postgresql/data/postgresql.conf
RUN sed -i -e"s/^#log_disconnections = off.*$/log_disconnections = on/" /var/lib/postgresql/data/postgresql.conf
RUN sed -i -e"s/^log_line_prefix = '\%t \[\%p-\%l\] \%q\%u@\%d '.*$/log_line_prefix = '\%t \[\%p\]: \[\%l-1\] user=\%u,db=\%d'/" /var/lib/postgresql/data/postgresql.conf
RUN sed -i -e"s/^#log_lock_waits = off.*$/log_lock_waits = on/" /var/lib/postgresql/data/postgresql.conf
RUN sed -i -e"s/^#log_temp_files = -1.*$/log_temp_files = 0/" /var/lib/postgresql/data/postgresql.conf
RUN sed -i -e"s/^#statement_timeout = 0.*$/statement_timeout = 1800000        # in milliseconds, 0 is disabled (current 30min)/" /var/lib/postgresql/data/postgresql.conf
RUN sed -i -e"s/^lc_messages = 'en_US.UTF-8'.*$/lc_messages = 'C'/" /var/lib/postgresql/data/postgresql.conf

# Performance Tuning
RUN sed -i -e"s/^max_connections = 100.*$/max_connections = 1000/" /var/lib/postgresql/data/postgresql.conf
RUN sed -i -e"s/^shared_buffers =.*$/shared_buffers = 16GB/" /var/lib/postgresql/data/postgresql.conf
RUN sed -i -e"s/^#effective_cache_size = 128MB.*$/effective_cache_size = 48GB/" /var/lib/postgresql/data/postgresql.conf
RUN sed -i -e"s/^#work_mem = 1MB.*$/work_mem = 16MB/" /var/lib/postgresql/data/postgresql.conf
RUN sed -i -e"s/^#maintenance_work_mem = 16MB.*$/maintenance_work_mem = 2GB/" /var/lib/postgresql/data/postgresql.conf
RUN sed -i -e"s/^#checkpoint_segments = .*$/checkpoint_segments = 32/" /var/lib/postgresql/data/postgresql.conf
RUN sed -i -e"s/^#checkpoint_completion_target = 0.5.*$/checkpoint_completion_target = 0.7/" /var/lib/postgresql/data/postgresql.conf
RUN sed -i -e"s/^#wal_buffers =.*$/wal_buffers = 16MB/" /var/lib/postgresql/data/postgresql.conf
RUN sed -i -e"s/^#default_statistics_target = 100.*$/default_statistics_target = 100/" /var/lib/postgresql/data/postgresql.conf


VOLUME ["/var/lib/postgresql/data", "/var/log/postgresql"]

CMD ["postgres"]

इस Dockerfile के साथ बिल्ड प्रक्रिया त्रुटि दिखाती है: sed: can't read /var/lib/postgresql/data/postgresql.conf: No such file or directory


1
एक विधि अधिकारी छवि का उपयोग करने, इसे शुरू है, साथ कनेक्ट अंदर docker exec -it container_id bashफिर अपने संशोधनों, तो करते docker commit container_id myuser/myimage_myPostegresql:myversionदस्तावेज़ नहीं देख docs.docker.com/reference/commandline/cli/#commit
user2915097

2
मुझे लगता है कि डॉक प्रतिमान के लाभों में से एक पूरे निर्माण की प्रक्रिया को स्वचालित करना है। जैसा कि एक अन्य छवि के साथ उल्लेख किया गया है paintedfox/postgresql, यह संभव है कि कॉन्फ़िगरेशन को सीधे डॉकरफाइल के भीतर बदल दिया जाए। मुझे लगता है कि आधिकारिक छवि के साथ भी संभव होना चाहिए।
सकर

sed विधि काम करना चाहिए, क्या आप अपने Dcokerfile या एक पूर्ण प्रतिलिपि प्रस्तुतकर्ता पोस्ट कर सकते हैं?
user2915097

जवाबों:


54

आपको जिस postgres:9.4छवि से विरासत में मिला है वह वॉल्यूम को घोषित करता है /var/lib/postgresql/data। यह अनिवार्य रूप से मतलब है कि आप अपनी छवि में किसी भी फाइल को उस पथ पर कॉपी नहीं कर सकते हैं; परिवर्तनों को छोड़ दिया जाएगा।

आपके पास कुछ विकल्प हैं:

  • आप रन-टाइम में वॉल्यूम के रूप में अपनी स्वयं की कॉन्फ़िगरेशन फ़ाइलों को जोड़ सकते हैं docker run -v postgresql.conf:/var/lib/postgresql/data/postgresql.conf ...। हालाँकि, मुझे यकीन नहीं है कि मौजूदा वॉल्यूम के साथ बातचीत कैसे होगी।

  • जब कंटेनर चालू हो, तो आप फ़ाइल को कॉपी कर सकते हैं। ऐसा करने के लिए, अपनी फ़ाइल को ऐसे स्थान पर बिल्ड में कॉपी करें, जो वॉल्यूम के नीचे नहीं है, फिर एंट्रीपॉइंट या cmd से एक स्क्रिप्ट को कॉल करें जो फ़ाइल को सही स्थान पर कॉपी कर देगा और पोस्टग्रेज करना शुरू कर देगा।

  • VOLUME घोषित होने से पहले (कुछ भी जोड़े जाने पर VOLUME निर्देश स्वत: रन-टाइम में स्वचालित रूप से कॉपी हो जाता है) से पहले प्रोजेक्ट को आधिकारिक छवि के पीछे क्लोन करें और अपनी खुद की कॉन्फिग फ़ाइल जोड़ने के लिए Dockerfile को एडिट करें।

  • डॉकटर-कंपोज फाइल में कमांड ऑप्शन में सभी कॉन्फिग चेंज पास करें

पसंद:

services:
  postgres:
    ...  
    command:
      - "postgres"
      - "-c"
      - "max_connections=1000"
      - "-c"
      - "shared_buffers=3GB"
      - "-c"
      ...

3
वह यह था, परिवर्तन डॉकरीफाइल के भीतर नहीं होना चाहिए। मैंने उन्हें एक स्क्रिप्ट में स्थानांतरित किया है और इसे एंट्रीपॉइंट से बुलाया है और यह अब ठीक काम करता है। जवाब के लिए धन्यवाद।
सकर

5
मैंने सिर्फ इनिट फ़ोल्डर "/docker-entrypoint-initdb.d/" के भीतर स्क्रिप्ट की प्रतिलिपि बनाई है और इस बार भी ठीक काम किया है। यह अजीब है, लेकिन ऐसा लगता है कि मैं डॉकरीफाइल के साथ छवि सेट करने पर बहुत ध्यान केंद्रित कर रहा था, जैसा कि मुझे सबसे अधिक छवियों के साथ करने के लिए उपयोग किया जाता है, कि मैं इनइट स्क्रिप्ट का उपयोग करके अपने पहले प्रयास के साथ कुछ याद किया।
सकर

"इसका अनिवार्य रूप से मतलब है कि आप अपनी छवि में किसी भी फ़ाइल को उस पथ पर कॉपी नहीं कर सकते; परिवर्तनों को छोड़ दिया जाएगा।" क्या आप बता सकते हैं कि ऐसा क्यों है?
इस्को

@ सिस्को आधिकारिक डॉक्स में वॉल्यूम को देखते हैं। मूल रूप से वॉल्यूम छवि में होस्ट पर संग्रहीत नहीं किए जाते हैं, इसलिए डेटा होस्ट पर सहेजा जाएगा, छवि में नहीं। डेटा रखने के लिए आपको कंटेनर को उसी वॉल्यूम से शुरू करना होगा।
एड्रियन मौट

i / /ib/postgres/data/pg_hba.conf में मैं केवल कनेक्शन स्वीकार करने के लिए सभी 192.168.0.0/0 md5 होस्ट करता हूं और सभी सभी md5 (डिफ़ॉल्ट रूप से) को होस्ट करता हूं। लेकिन प्रभाव
मत

83

डॉकर कम्पोज़ के साथ

डॉकर कम्पोज़ के साथ काम करते समय, आप पोस्टग्रेज को कॉन्फ़िगर करने के लिए command: postgres -c option=valueअपने में उपयोग कर सकते हैं docker-compose.yml

उदाहरण के लिए, यह Postgres को किसी फ़ाइल में लॉग करता है:

command: postgres -c logging_collector=on -c log_destination=stderr -c log_directory=/logs

Vojtech Vitek के उत्तर को अपनाना , आप उपयोग कर सकते हैं

command: postgres -c config_file=/etc/postgresql.conf

विन्यास फाइल को बदलने के लिए Postgres का उपयोग करेगा। आप वॉल्यूम के साथ अपनी कस्टम कॉन्फ़िग फ़ाइल माउंट करेंगे:

volumes:
   - ./customPostgresql.conf:/etc/postgresql.conf

docker-compose.ymlपोस्टग्रेज को कॉन्फ़िगर करने का तरीका दिखाते हुए यहां मेरा आवेदन दिया गया है:

# Start the app using docker-compose pull && docker-compose up to make sure you have the latest image
version: '2.1'
services:
  myApp:
    image: registry.gitlab.com/bullbytes/myApp:latest
    networks:
      - myApp-network
  db:
     image: postgres:9.6.1
     # Make Postgres log to a file.
     # More on logging with Postgres: https://www.postgresql.org/docs/current/static/runtime-config-logging.html
     command: postgres -c logging_collector=on -c log_destination=stderr -c log_directory=/logs
     environment:
       # Provide the password via an environment variable. If the variable is unset or empty, use a default password
       - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-4WXUms893U6j4GE&Hvk3S*hqcqebFgo!vZi}
     # If on a non-Linux OS, make sure you share the drive used here. Go to Docker's settings -> Shared Drives
     volumes:
       # Persist the data between container invocations
       - postgresVolume:/var/lib/postgresql/data
       - ./logs:/logs
     networks:
       myApp-network:
         # Our application can communicate with the database using this hostname
         aliases:
           - postgresForMyApp
networks:
  myApp-network:
    driver: bridge
# Creates a named volume to persist our data. When on a non-Linux OS, the volume's data will be in the Docker VM
# (e.g., MobyLinuxVM) in /var/lib/docker/volumes/
volumes:
  postgresVolume:

लॉग डायरेक्टरी को लिखने की अनुमति

ध्यान दें कि लिनक्स पर, होस्ट पर लॉग डायरेक्टरी के पास सही अनुमति होनी चाहिए। अन्यथा आपको थोड़ी भ्रामक त्रुटि मिलेगी

FATAL: लॉग फाइल नहीं खोल सका "/logs/postgresql-2017-02-04_115222.log": अनुमति अस्वीकृत

मैं भ्रामक कहता हूं, क्योंकि त्रुटि संदेश बताता है कि कंटेनर में निर्देशिका की गलत अनुमति है, जब वास्तव में मेजबान पर निर्देशिका लिखने की अनुमति देती है।

इसे ठीक करने के लिए, मैंने होस्ट का उपयोग करके सही अनुमतियों को सेट किया

chgroup ./logs docker && chmod 770 ./logs

क्या आप स्टडआउट के बजाय किसी फ़ाइल लॉग को पोस्टग्रेज बनाने की सलाह देंगे, जिससे निपटने के लिए डॉक लॉग कमांड का उपयोग करना होगा? Github मुद्दे में crosslinking के लिए यश !
12

1
मैंने यह तय नहीं किया है कि डॉकरी लॉग्स को फाइल करना या उपयोग करना बेहतर है या नहीं।
मथायस ब्रौन

आपने पासवर्ड जोड़ा है, जिसे आप शायद यहाँ पर
देखना चाहेंगे

3
@vidstige: मैं पासवर्ड के रूप में इस यादृच्छिक स्ट्रिंग का उपयोग नहीं करता, यह केवल प्रदर्शन के लिए है।
मथायस ब्रौन

1
@Gherman: क्या आपने इसे अपने Dockerfile में जोड़ा है? क्योंकि आपको नहीं करना चाहिए। मेरा उत्तर उपयोग करता है docker-compose.yml
मथायस ब्रौन

39

कस्टम कस्टमर postgresql.conf को डॉकटर कंटेनर में इंजेक्ट करें

डिफ़ॉल्ट postgresql.confफ़ाइल PGDATAडीआईआर ( /var/lib/postgresql/data) के भीतर रहती है , जो चीजों को और अधिक जटिल बना देती है, विशेषकर जब पहली बार कंटेनर को चलाने के बाद, जब से docker-entrypoint.shरैपर डीर आरंभीकरण के initdbलिए कदम को लागू करता PGDATAहै।

लगातार Docker में PostgreSQL विन्यास को अनुकूलित करने के लिए, मैं config_fileइस तरह से Docker संस्करणों के साथ postgres विकल्प का उपयोग करने का सुझाव देता हूं :

उत्पादन डेटाबेस (स्थायी मात्रा के रूप में पीजीडीटीए धीर)

docker run -d \
-v $CUSTOM_CONFIG:/etc/postgresql.conf \
-v $CUSTOM_DATADIR:/var/lib/postgresql/data \
-e POSTGRES_USER=postgres \
-p 5432:5432 \
--name postgres \
postgres:9.6 postgres -c config_file=/etc/postgresql.conf

परीक्षण डेटाबेस (PGDATA dir के बाद छोड़ दिया जाएगा docker rm)

docker run -d \
-v $CUSTOM_CONFIG:/etc/postgresql.conf \
-e POSTGRES_USER=postgres \
--name postgres \
postgres:9.6 postgres -c config_file=/etc/postgresql.conf

डिबगिंग

  1. सर्वर लॉग को सीधे देखने के लिए कमांड -dसे (डिटैच विकल्प) निकालें docker run
  2. Psql क्लाइंट के साथ पोस्टग्रेज सर्वर से कनेक्ट करें और कॉन्फ़िगरेशन को क्वेरी करें:

    docker run -it --rm --link postgres:postgres postgres:9.6 sh -c 'exec psql -h $POSTGRES_PORT_5432_TCP_ADDR -p $POSTGRES_PORT_5432_TCP_PORT -U postgres'
    
    psql (9.6.0)
    Type "help" for help.
    
    postgres=# SHOW all;

30

जब आप आधिकारिक प्रविष्टि को चलाते हैं (AKA जब आप कंटेनर लॉन्च करते हैं), यह ( डिफ़ॉल्ट रूप से) initdbमें चलता है , और फिर यह उस निर्देशिका में इन 2 फ़ाइलों को संग्रहीत करता है:$PGDATA/var/lib/postgresql/data

  • postgresql.conf डिफ़ॉल्ट मैनुअल सेटिंग्स के साथ।
  • postgresql.auto.confसेटिंग्स के साथ ALTER SYSTEMआदेशों के साथ स्वचालित रूप से ओवरराइड करें।

एंट्रीपॉइंट किसी भी /docker-entrypoint-initdb.d/*.{sh,sql}फाइल को निष्पादित करता है।

इसका मतलब यह है कि आप उस फ़ोल्डर में एक शेल / एसक्यूएल स्क्रिप्ट की आपूर्ति कर सकते हैं जो सर्वर को अगले बूट के लिए कॉन्फ़िगर करता है (जो डीबी आरंभीकरण के तुरंत बाद होगा, या अगली बार जब आप कंटेनर को बूट करते हैं)।

उदाहरण:

conf.sql फ़ाइल:

ALTER SYSTEM SET max_connections = 6;
ALTER SYSTEM RESET shared_buffers;

Dockerfile फ़ाइल:

FROM posgres:9.6-alpine
COPY *.sql /docker-entrypoint-initdb.d/
RUN chmod a+r /docker-entrypoint-initdb.d/*

और फिर आपको conf.sqlपहले से मौजूद डेटाबेस में मैन्युअल रूप से निष्पादित करना होगा । चूँकि कॉन्फ़िगरेशन वॉल्यूम में संग्रहीत है, यह पुनर्वित्त से बचेगा।


एक अन्य विकल्प यह है -cकि आप जितनी बार चाहें, झंडे को पास करें :

docker container run -d postgres -c max_connections=6 -c log_lock_waits=on

इस तरह आपको एक नई छवि बनाने की आवश्यकता नहीं है, और आपको पहले से मौजूद या डेटाबेस की परवाह करने की आवश्यकता नहीं है; सभी प्रभावित होंगे।


2
यह आखिरी, पासिंग-सी, मेरा पसंदीदा है। यह अलग-अलग वातावरण के लिए उत्पन्न करने के लिए बहुत साफ और सरल है।
महाकाव्य_फिल

10

आप अपने कस्टम postgresql.confको कंटेनर के अंदर एक अस्थायी फ़ाइल में रख सकते हैं , और रनटाइम पर डिफ़ॉल्ट कॉन्फ़िगरेशन को अधिलेखित कर सकते हैं।

ऐसा करने के लिए :

  • अपने कस्टम postgresql.confको अपने कंटेनर के अंदर कॉपी करें
  • updateConfig.shफ़ाइल को कॉपी करें/docker-entrypoint-initdb.d/

Dockerfile

FROM postgres:9.6

COPY postgresql.conf      /tmp/postgresql.conf
COPY updateConfig.sh      /docker-entrypoint-initdb.d/_updateConfig.sh

updateConfig.sh

#!/usr/bin/env bash

cat /tmp/postgresql.conf > /var/lib/postgresql/data/postgresql.conf

रनटाइम के दौरान, कंटेनर स्क्रिप्ट को निष्पादित करेगा /docker-entrypoint-initdb.d/और yout कस्टम एक के साथ डिफ़ॉल्ट कॉन्फ़िगरेशन को अधिलेखित करेगा।


दूसरी कॉपी कमांड में "_" क्यों? यह नहीं होना चाहिए /docker-entrypoint-initdb.d/updateConfig.sh:?
फर्नांडो कैस्टिला ऑस्पिना

3
ऐसा इसलिए है क्योंकि डॉकटर-एंट्रीपॉइंट-initdb.d / फ़ोल्डर वर्णमाला क्रम में स्क्रिप्ट निष्पादित करते हैं। और मैं इस स्क्रिप्ट को दूसरों के सामने लागू करना चाहता हूं।
अल्फा

tnx मैं यह भूल गया कि प्रतिलिपि ने अंडरस्कोर का उपयोग करने के लिए फ़ाइल का नाम बदला
फर्नांडो कैस्टिला ऑस्पिना

9

मैंने सभी उत्तरों को देखा और एक और विकल्प बचा है। आप अपने सीएमडी मूल्य को डॉक फाइल में बदल सकते हैं (यह सबसे अच्छा नहीं है, लेकिन फिर भी अपने लक्ष्य को प्राप्त करने का संभव तरीका है)।

मूल रूप से हमें जरूरत है

  • Docker कंटेनर में कॉन्फिग फाइल कॉपी करें
  • ओवरराइड पोस्टग्रैज स्टार्ट ऑप्शन

डॉकर फ़ाइल उदाहरण:

FROM postgres:9.6
USER postgres

# Copy postgres config file into container
COPY postgresql.conf /etc/postgresql

# Override default postgres config file
CMD ["postgres", "-c", "config_file=/etc/postgresql/postgresql.conf"]

हालांकि मुझे लगता है कि माथियास ब्रौन द्वारा प्रस्तावित command: postgres -c config_file=/etc/postgresql/postgresql.confआपकी docker-compose.ymlफ़ाइल में उपयोग करना सबसे अच्छा विकल्प है।


2

इस समस्या का एक काफी कम-तकनीकी समाधान लगता है सेवा को घोषित करने के लिए (मैं AWS और एक yaml फ़ाइल पर झुंड का उपयोग कर रहा हूं) अपने डेटाबेस फ़ाइलों के साथ एक निरंतर मात्रा में माउंट किया गया है (यहां AWS EFS को क्लाउडस्टार द्वारा निरूपित किया गया है: aws ड्राइवर विनिर्देश)।

  version: '3.3'
  services:
    database:
      image: postgres:latest
      volumes:
        - postgresql:/var/lib/postgresql
        - postgresql_data:/var/lib/postgresql/data
    volumes:
       postgresql:
         driver: "cloudstor:aws" 
       postgresql_data:
         driver: "cloudstor:aws"
  1. Db इमेज डिफॉल्ट सेटिंग्स के साथ इनिशियलाइज्ड होकर आता है।
  2. आप कन्टेनर के अंदर कॉन्फिग सेटिंग्स को एडिट करते हैं, उदाहरण के लिए यदि आप समवर्ती कनेक्शनों की अधिकतम संख्या बढ़ाना चाहते हैं, जिसके लिए रिस्टार्ट की आवश्यकता होती है
  3. चल रहे कंटेनर को रोकें (या सेवा को शून्य पर ले जाएं और फिर वापस एक पर ले जाएं)
  4. झुंड एक नए कंटेनर को जन्म देता है, जो इस बार आपके स्थायी कॉन्फ़िगरेशन सेटिंग्स को चुनता है और उन्हें आसानी से लागू करता है।

आपके कॉन्फ़िगरेशन को बनाए रखने का एक सुखद पक्ष प्रभाव यह है कि यह आपके डेटाबेस को भी बनाए रखता है (या क्या यह दूसरा तरीका है;


2

मेरा समाधान उन सहयोगियों के लिए है, जिन्हें docker-entrypoint -itdb.d को लॉन्च करने से पहले कॉन्फ़िगरेशन में परिवर्तन करने की आवश्यकता है

मुझे _ साझा_प्रभार_ पुस्तकालय ’की स्थापना को बदलने की आवश्यकता थी, इसलिए काम के दौरान यह पहले से ही नई लाइब्रेरी में पहले से लोड है और docker-entrypoint-initdb.d में कोड इसका उपयोग कर सकता है।

इसलिए मैंने अभी डॉकरीफाइल में postgresql.conf.sample फ़ाइल को पैच किया:

RUN echo "shared_preload_libraries='citus,pg_cron'" >> /usr/share/postgresql/postgresql.conf.sample
RUN echo "cron.database_name='newbie'" >> /usr/share/postgresql/postgresql.conf.sample

और इस पैच के साथ डॉक-एंट्री पॉइंट-initdb.d / / में .sql फ़ाइल में एक्सटेंशन जोड़ना संभव हो जाता है:

CREATE EXTENSION pg_cron;

1

यह मेरे लिए काम करता है:

FROM postgres:9.6
USER postgres

# Copy postgres config file into container
COPY postgresql.conf /etc/postgresql

# Override default postgres config file
CMD ["postgres", "-c", "config_file=/etc/postgresql/postgresql.conf"]

इसे कोई अपवाह क्यों नहीं मिला? यह बहुत ही पवित्र प्रस्ताव है यहाँ ... धन्यवाद।
पाफलो

0

डॉक कंपोज़ का उपयोग करके आप एक वॉल्यूम माउंट कर सकते हैं postgresql.auto.conf। उदाहरण:

version: '2'

services:
  db:
    image: postgres:10.9-alpine
    volumes:
      - postgres:/var/lib/postgresql/data:z
      - ./docker/postgres/postgresql.auto.conf:/var/lib/postgresql/data/postgresql.auto.conf
    ports:
      - 5432:5432

postgresql.auto.confयह ओवरराइट होने पर आपको एडिट नहीं करना चाहिए । postgresql.confउसी स्थान पर उपयोग करें ।
बैसचल्ड

0

मैं भी आधिकारिक छवि का उपयोग कर रहा था ( FROM postgres) और मैं निम्नलिखित कमांड्स को निष्पादित करके कॉन्फ़िगरेशन को बदलने में सक्षम था।

पहली बात यह है कि PostgreSQL कॉन्फिग फ़ाइल का पता लगाएं। यह आपके रनिंग डेटाबेस में इस कमांड को निष्पादित करके किया जा सकता है।

SHOW config_file;

मैं अपना मामला वापस करता हूं /data/postgres/postgresql.conf

अगला कदम यह पता लगाना है कि आपके चलने वाले PostgreSQL docker कंटेनर का हैश क्या है।

docker ps -a

यह सभी चलने वाले कंटेनरों की एक सूची वापस करना चाहिए। मेरे मामले में ऐसा दिखता है।

...
0ba35e5427d9    postgres    "docker-entrypoint.s…" ....
...

अब आपको निष्पादित करके अपने कंटेनर के अंदर बैश में जाना है:

docker exec -it 0ba35e5427d9 /bin/bash

कंटेनर के अंदर की जाँच करें कि क्या विन्यास सही रास्ते पर है और इसे प्रदर्शित करें।

cat /data/postgres/postgresql.conf

मैं अधिकतम कनेक्शन 100 से 1000 और साझा बफर को 128 एमबी से 3 जीबी तक बदलना चाहता था। सेड कमांड के साथ मैं एक सर्च कर सकता हूं और इसी वेरिएबल के साथ इनसो को बदल सकता है।

sed -i -e"s/^max_connections = 100.*$/max_connections = 1000/" /data/postgres/postgresql.conf
sed -i -e"s/^shared_buffers = 128MB.*$/shared_buffers = 3GB/" /data/postgres/postgresql.conf

आखिरी चीज जो हमें करनी है वह है कंटेनर के भीतर डेटाबेस को रिस्टार्ट करना। पता करें कि आप अपने द्वारा उपयोग किए जा रहे पोस्टग्रेज का कौन सा संस्करण बनाते हैं।

cd /usr/lib/postgresql/
ls 

मेरे मामले में इसकी 12 अब आप जगह में सही संस्करण के साथ निम्नलिखित कमांड को निष्पादित करके डेटाबेस को पुनरारंभ कर सकते हैं।

su - postgres -c "PGDATA=$PGDATA /usr/lib/postgresql/12/bin/pg_ctl -w restart"
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.