{"id":14063361,"url":"https://github.com/ghusta/docker-postgres-world-db","last_synced_at":"2025-04-09T12:04:07.505Z","repository":{"id":37580150,"uuid":"91439947","full_name":"ghusta/docker-postgres-world-db","owner":"ghusta","description":"Example Database for PostgreSQL : World DB","archived":false,"fork":false,"pushed_at":"2025-03-02T13:50:13.000Z","size":530,"stargazers_count":45,"open_issues_count":2,"forks_count":35,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T11:05:47.735Z","etag":null,"topics":["database","docker","example","postgresql"],"latest_commit_sha":null,"homepage":"","language":"PLpgSQL","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/ghusta.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2017-05-16T09:23:41.000Z","updated_at":"2025-03-25T19:52:40.000Z","dependencies_parsed_at":"2024-01-14T12:25:41.163Z","dependency_job_id":"b19095a6-bcd8-4fad-aa5b-c7c5b176c75d","html_url":"https://github.com/ghusta/docker-postgres-world-db","commit_stats":null,"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghusta%2Fdocker-postgres-world-db","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghusta%2Fdocker-postgres-world-db/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghusta%2Fdocker-postgres-world-db/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghusta%2Fdocker-postgres-world-db/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ghusta","download_url":"https://codeload.github.com/ghusta/docker-postgres-world-db/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248036064,"owners_count":21037092,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["database","docker","example","postgresql"],"created_at":"2024-08-13T07:03:17.957Z","updated_at":"2025-04-09T12:04:07.489Z","avatar_url":"https://github.com/ghusta.png","language":"PLpgSQL","readme":"# postgres-world-db\n\n[![Build Status](https://github.com/ghusta/docker-postgres-world-db/actions/workflows/docker-image.yml/badge.svg)](https://github.com/ghusta/docker-postgres-world-db/actions/workflows/docker-image.yml)\n[![Docker Pulls](https://img.shields.io/docker/pulls/ghusta/postgres-world-db.svg?logo=docker)](https://hub.docker.com/r/ghusta/postgres-world-db)\n[![GitHub release](https://img.shields.io/github/v/release/ghusta/docker-postgres-world-db?sort=semver\u0026logo=GitHub)](https://github.com/ghusta/docker-postgres-world-db/releases)\n\nExample Database for [PostgreSQL](https://www.postgresql.org/) : World DB\n\nDatabase script downloaded at : http://pgfoundry.org/frs/?group_id=1000150\u0026release_id=366#world-world-1.0-title-content\n\nSee also PostgreSQL [Sample Databases](https://wiki.postgresql.org/wiki/Sample_Databases).\n\n# Database details\n\n**Important note** : from version 2.0, tables and columns names use [_snake case_](https://en.wikipedia.org/wiki/Snake_case).\n This version is incompatible with version 1.x.\n\n## Default parameters\n\n- database : world-db\n- user : world\n- password : world123\n\n## Schema\n\n- public\n\n## Tables\nThis database contains 4 tables :\n\n- city\n- country\n- country_language\n- country_flag\n\n## Relationships\n\n- country_language -\u003e country (country_language_country_code_fkey)\n- city -\u003e country (country_fk)\n- country -\u003e city (country_capital_fkey)\n\n# Run a Docker container\n\nYou can run a Docker container with this command (replace _xxxx_ by your local port) :\n\n```shell\ndocker run -d -p xxxx:5432 ghusta/postgres-world-db:2.12\n```\n\n# PostgreSQL configuration\n\nIf you need to inspect the PostgreSQL server configuration, you can print this file : `/var/lib/posgtresql/data/postgresql.conf`.\n\nAll settings are documented here : https://www.postgresql.org/docs/current/runtime-config.html\n\nWith Docker, you can run :\n\n```shell\ndocker exec \u003cmy-container-name\u003e cat /var/lib/postgresql/data/postgresql.conf\n```\n\n## Log all statements\n\nTo log all statements, you can activate this line in the configuration :\n\n`log_min_duration_statement = 0`\n\n## Log categories of statements\n\nYou can also log only some categories of statements with `log_statement`.\n\nValid values are `none, ddl, mod, all`. Default is `none`.\n\nSee details : https://www.postgresql.org/docs/current/runtime-config-logging.html\n\n# Test it\n\n## With the psql CLI command\n\n```shell\ndocker exec -it \u003ccontainer_name\u003e psql -d world-db -U world\n```\n\nThen try a command, like :\n\n### List of relations\n\n```PLSQL\npsql (15.0 (Debian 15.0-1.pgdg110+1))\nType \"help\" for help.\n\nworld-db=# \\d\n             List of relations\n Schema |       Name       | Type  | Owner\n--------+------------------+-------+-------\n public | city             | table | world\n public | country          | table | world\n public | country_flag     | table | world\n public | country_language | table | world\n(4 rows)\n```\n\n### List of schemas\n\n```PLSQL\nworld-db=# \\dn\nList of schemas\n  Name  | Owner\n--------+-------\n public | world\n(1 row)\n```\n\n### Describe the city table\n\n```PLSQL\nworld-db=# \\d+ city\n...\n```\n\n### A simple query\n\n```PLSQL\nworld-db=# select * from city limit 10;\n  1 | Kabul          | AFG          | Kabol         |    1780000\n  2 | Qandahar       | AFG          | Qandahar      |     237500\n  3 | Herat          | AFG          | Herat         |     186800\n  4 | Mazar-e-Sharif | AFG          | Balkh         |     127800\n  5 | Amsterdam      | NLD          | Noord-Holland |     731200\n  6 | Rotterdam      | NLD          | Zuid-Holland  |     593321\n  7 | Haag           | NLD          | Zuid-Holland  |     440900\n  8 | Utrecht        | NLD          | Utrecht       |     234323\n  9 | Eindhoven      | NLD          | Noord-Brabant |     201843\n 10 | Tilburg        | NLD          | Noord-Brabant |     193238\n```\n\n## With Java\n\n### Plain Java with JDBC\n\nFirst add the [PostgreSQL JDBC Driver](https://jdbc.postgresql.org/), with Maven for example : [org.postgresql » postgresql](https://mvnrepository.com/artifact/org.postgresql/postgresql).\n\nThen execute a test query with :\n\n```java\npackage org.example;\n\nimport java.sql.Connection;\nimport java.sql.DriverManager;\nimport java.sql.ResultSet;\nimport java.sql.SQLException;\nimport java.sql.Statement;\n\npublic class JdbcDemo {\n\n    public static void main(String[] args) {\n        String jdbcUrl = \"jdbc:postgresql://localhost:5432/world-db\";\n        String user = \"world\";\n        String password = \"world123\";\n\n        try (Connection conn = DriverManager.getConnection(jdbcUrl, user, password)) {\n            String query = \"select count(*) from city\";\n            try (Statement stmt = conn.createStatement()) {\n                ResultSet rs = stmt.executeQuery(query);\n                while (rs.next()) {\n                    int count = rs.getInt(1);\n                    System.out.println(\"Count = \" + count);\n                }\n            } catch (SQLException e) {\n                e.printStackTrace();\n            }\n        } catch (SQLException e) {\n            e.printStackTrace();\n        }\n    }\n\n}\n```\n\n### Spring Boot\n\nInitialize a [Spring Boot project](https://start.spring.io/) with dependencies _PostgreSQL Driver_ and [_Spring Data JPA_](https://spring.io/projects/spring-data-jpa) (or [_Spring Data JDBC_](https://spring.io/projects/spring-data-jdbc) if you want to keep simple).\n\nAdd these properties in _application.properties_ :\n\n- `spring.datasource.url=jdbc:postgresql://localhost:5432/world-db`\n- `spring.datasource.username=world`\n- `spring.datasource.password=world123`\n\nThen just add JPA entities for each table (City, Country), and interfaces for each DAO which extends `JpaRepository`.\n\n## With Python\n\nInstall [psycopg 3](https://pypi.org/project/psycopg/), a PostgreSQL database adapter for Python.\n\n\u003e pip install psycopg\n\nThen create a connection...\n\n```python\nimport psycopg\n\nDB_HOST = \"localhost\"\nDB_PORT = \"5432\"\nDB_NAME = \"world-db\"\nDB_USER = \"world\"\nDB_PASS = \"world123\"\n\nwith psycopg.connect(dbname=DB_NAME, user=DB_USER, password=DB_PASS, host=DB_HOST, port=DB_PORT) as conn:\n\n    with conn.cursor() as cur:\n        cur.execute(\"select count(*) from city\")\n        row = cur.fetchone()\n        print('Count = ', row[0])\n\n```\n\n# Alternatives\n\nYou can find alternative DBMS or databases examples [at this page](ALTERNATIVES.md).\n","funding_links":[],"categories":["PLpgSQL"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghusta%2Fdocker-postgres-world-db","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fghusta%2Fdocker-postgres-world-db","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghusta%2Fdocker-postgres-world-db/lists"}