{"id":21017421,"url":"https://github.com/mkader/postgresql","last_synced_at":"2026-05-17T17:46:09.634Z","repository":{"id":163089014,"uuid":"637946157","full_name":"mkader/postgresql","owner":"mkader","description":null,"archived":false,"fork":false,"pushed_at":"2023-05-09T21:25:22.000Z","size":130,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-19T09:49:11.921Z","etag":null,"topics":["azure","learning","microsoft-learning"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mkader.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-08T18:49:06.000Z","updated_at":"2023-12-28T21:27:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"800b7b5f-2e59-4d3f-8334-a3836b506d5e","html_url":"https://github.com/mkader/postgresql","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mkader/postgresql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkader%2Fpostgresql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkader%2Fpostgresql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkader%2Fpostgresql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkader%2Fpostgresql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mkader","download_url":"https://codeload.github.com/mkader/postgresql/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkader%2Fpostgresql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33148765,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-17T09:28:26.183Z","status":"ssl_error","status_checked_at":"2026-05-17T09:27:52.702Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["azure","learning","microsoft-learning"],"created_at":"2024-11-19T10:19:23.566Z","updated_at":"2026-05-17T17:46:04.624Z","avatar_url":"https://github.com/mkader.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Local \u0026 Azure PostgreSQL Database setup with Python code to Access\n\n    Types of databases\n        Non-relational / document databases: MongoDB, Firebase, CouchDB, etc.\n        Relational databases: MySQL, SQLite, PostgreSQL, etc.\n   \n    Dockerfile\n        ARG IMAGE=bullseye =\u003e The bullseye Docker image is based on Debian 11 Linux distribution.\n        FROM mcr.microsoft.com/devcontainers/${IMAGE} =\u003e The image from the MS Container Registry for development containers. \n        ENV PYTHONUNBUFFERED 1 =\u003e Python output is unbuffered and sent directly to the console, which can be helpful when debugging applications.\n        RUN apt-get update \u0026\u0026 export DEBIAN_FRONTEND=noninteractive \\ =\u003e used to prevent prompts from appearing during the installation process.\n            \u0026\u0026 apt-get -y install --no-install-recommends postgresql-client \\ =\u003einstalls the client package using apt-get, provides the psql command-line tool. \n            \u0026\u0026 apt-get clean -y \u0026\u0026 rm -rf /var/lib/apt/lists/* =\u003e clean up the package cache and remove unnecessary files to reduce the size of the Docker image.\n\n    docker-compose.yaml\n        services: =\u003e This defines two services - app and db.\n        app:\n            build:\n                context: ..\n                dockerfile: .devcontainer/Dockerfile\n                args:\n                    IMAGE: python:3.11\n                volumes:\n                    - ..:/workspace:cached\n                command: sleep infinity\n                network_mode: service:db\n            The app service builds the Docker image from the dockerfile using the Python version. \n            \n            The volumes section mounts the parent directory (..) of the .devcontainer directory to the /workspace directory in the ontainer, \n            allowing the local code changes to be reflected in the container. \n            \n            The command section keeps the container running indefinitely, and network_mode section sets the network mode to be the same as the db service, allowing them to communicate with each other.       \n        db:\n            image: postgres:latest\n            restart: unless-stopped\n            volumes:\n                - postgres-data:/var/lib/postgresql/data\n            environment:\n                POSTGRES_DB: postgres\n                POSTGRES_USER: admin\n                POSTGRES_PASSWORD: LocalPasswordOnly\n            The db service uses the latest PostgreSQL image from Docker Hub,\n            \n            The volumes section mounts the postgres-data volume to the /var/lib/postgresql/data directory in the container. \n            \n            The environment section sets the POSTGRES_DB, USER, PASSWORD variables, which are used to create a new PostgreSQL database and user.\n        volumes:\n            postgres-data: \n            A named volume called postgres-data, which can be used to persist data across container restarts. \n            \n            Any data that is stored in the /var/lib/postgresql/data directory in the db service will be persisted in this volume.\n\n    devcontainer.json -  is a configuration file used by VSC to define a development container for a project. \n        \n        It specifies the dev environment, including the Docker image to use, the container configuration, and the extensions to install in the container.\n        \n        Configuration needed to work with the Docker files:\n            \"name\": \"python-db-copilot\"  =\u003e Sets the name of the development container to python-db-copilot.\n            \n            \"dockerComposeFile\": \"docker-compose.yaml\" =\u003e Specifies the Docker Compose file to use when building the dev container.\n            \n            \"service\": \"app\" =\u003e Specifies which service in the Docker Compose file to use as the main dev environment.\n            \n            \"workspaceFolder\": \"/workspace\" =\u003e the workspace folder in the container that will be mapped to the local project directory.\n            \n            \"forwardPorts\": [5432] =\u003e which ports to forward from the container to the local machine (5432 is the default PostgreSQL port).\n            \n            \"portsAttributes\": { \"5432\": {\"label\": \"PostgreSQL port\", \"onAutoForward\": \"silent\"}} \n                Provides additional attributes for the forwarded port. In this case, a label to identify the forwarded port and sets the onAutoForward attribute to \"silent\", which means that VSC Code will automatically forward the port without prompting the user.\n\n        Installing extensions:\n            \"ms-python.python\" =\u003e Official Python extension for VSC, it provides features such as linting, debugging, code completion for Python.\n            \n            \"ms-python.vscode-pylance\" =\u003e An optional language server for Python that provides more advanced type checking and autocomplete features.\n            \n            \"charliermarsh.ruff\" =\u003e This extension provides support for the Ruff database migration tool.\n           \n            \"ms-python.black-formatter\" =\u003e  Provides support for the Black code formatter for Python.\n           \n            \"mtxr.sqltools\" =\u003e General-purpose SQL extension that provides features(syntax highlighting, code completion, db management.)\n           \n            \"mtxr.sqltools-driver-pg\" =\u003e PostgreSQL driver for the SQL Tools extension.\n           \n            \"ms-vscode.vscode-node-azure-pack\" =\u003e Provides support for developing and deploying Node.js applications to Azure.\n\n        Configuring SQLTools extension:\n            \"sqltools.connections\": [\n                {\n                    \"name\": \"Local database\",\n                    \"driver\": \"PostgreSQL\",\n                    \"server\": \"localhost\",\n                    \"port\": 5432,\n                    \"database\": \"postgres\",\n                    \"username\": \"admin\",\n                    \"password\": \"LocalPasswordOnly\"\n                }\n\n    SQLTools extension: Connect to local or cloud databases. Create, Read, Write database\n![alt](https://raw.githubusercontent.com/mkader/postgresql/main/github_codespace_sqltools.png)\n    \nDatabases in Python\n    \n    create .env  file =\u003e DBHOST=..., DBNAME=...\n    \n    create requirements.txt\n        psycopg2: PostgreSQL db adapter for Python, allows Python to connect and interact with PostgreSQL db.\n        \n        python-dotenv: Allows you to load environment variables from a .env file into your Python application. This can be useful for storing sensitive information like db credentials or API keys.\n        \n        SQLAlchemy: ORM (object-relational mapping) library for Python. It allows you to interact with db using Python code, a provides a high-level abstraction over SQL.\n        \n        mimesis: Python library for generating fake data. It can be useful for testing or populating a db with realistic-looking data.\n        \n        faker: Python library for generating fake data. It can also be useful for testing or populating a db with realistic-looking data.    \n\n        pip install -r requirements.txt\n\n    PostgreSQL in Python\n        Option 1: use psycopg2 SQL directly. (psycopg.py)\n        Option 2: Accessing DBs from Web Apps: ORM , SQLAlchemy (pyday_sqlalchemy.py)\n    \nHosting DB (PostgreSQL) on Azure\n\n    Managed services for PostgreSQL on Azure\n        Option\t                                        Description\n        Azure Database for PostgreSQL – Single Server\tMS's original offering. No longer recommended for new apps.\n        \n        Azure Database for PostgreSQL – Flexible Server\tMS's most recent PostgreSQL offering. Fully managed service with vertical scaling.\n        \n        Azure Cosmos DB for PostgreSQL\t                Distributed db using PostgreSQL and the Citus extension. Can scale horizontally.\n\n        🔗 aka.ms/flex-vs-single Comparison: Flexible vs. Single Server\n        🔗 aka.ms/flex-vs-cosmos Cosmos DB for PostgreSQL vs. Flex Server\n\n    Provisioning PostgreSQL in Portal\n        Portal -\u003e \"Select Azure Database for PostgreSQL – Flexible Server\" resource -\u003e Development -\u003e Configure without Firewall\n        \n        Update Azure Connection setting in .env file\n        \n        Update your client ip address, check \"Allow public access from any Azure ...\" in Azure PostgreSQL Server Networking\n        \n        Codespace Terminal \"curl ifconfig.me\", get ip addess \u0026 update in firewall rule in Azure PostgreSQL Server Networking\n\n        DATABASE_URI += \"?sslmode=require\" =\u003e Adds SSL mode require, connecting to the production server is to enforce SSL\n  \n![alt](https://raw.githubusercontent.com/mkader/postgresql/main/azure_postgresql_resource.PNG)\n\nNext\n    Writing Django Apps Django framework  - https://github.com/mkader/python_django_postgresql_azure_app\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkader%2Fpostgresql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmkader%2Fpostgresql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkader%2Fpostgresql/lists"}