Commands providing shortcuts to common Postgres introspection queries (Swift port of heroku-pg-extras)

Overview

swift-pg-extras

Commands providing shortcuts to common Postgres introspection queries. This package is a port of heroku-pg-extras.

Most of the commands have been ported, except for a few that need special database configuration or where it's unclear how to port them.

Installation

Via mint:

mint install finestructure/swift-pg-extras

Or clone the repository and run/install it like any other Swift command line utility.

How to run

Get a list of all available commands:

pg-extras --help

Example command:

pg-extras cache-hit -c .credentials
+----------------+---------------------+
| Name           | Ratio               |
+----------------+---------------------+
| index hit rate | 0.9993522581171029  |
| table hit rate | 0.9993522581171029  |
+----------------+---------------------+

where .credentials containes your Postgres database connection details:

{
    "host": "localhost",
    "port": 5432,
    "username": "foo",
    "database": "bar",
    "password": "pass"
}

The credentials file supports an optional field tls to disable or require TLS:

{
    ...
    "tls": "require"
}

Available commands

  • bloat
  • blocking
  • cache-hit
  • calls
    • requires create extension pg_stat_statements and loading pg_stat_statements via shared_preload_libraries
  • extensions
    • ERROR: unrecognized configuration parameter "extwlist.extensions"
  • fdwsql
    • looks like it requires postgres_fdw setup
  • index-size
  • index-usage
  • locks
  • long-running-queries
  • mandelbrot
    • gimmick
  • records-rank
  • seq-scans
  • table-indexes-size
  • table-size
  • total-index-size
  • total-table-size
  • outliers
    • requires create extension pg_stat_statements and loading pg_stat_statements via shared_preload_libraries
  • unused-indexes
  • user-connections
    • unsure how this works in the original, no SQL in command
  • vacuum-stats

Why port it to Swift?

The original project requires heroku to be installed and I've found one other project that makes it independent to it can be installed with npm.

My setup doesn't include running JavaScript tools, so having a Swift binary around is much easier for me personally and I suspect this might be true for others as well.

Moreover, I think there could be ways this package could become a module (via a vapor-pg-extras package that uses it) that you load into a Vapor project such that you can get more detailed performance metrics about your Postgres database automatically. For that it is useful to have a base module as a Swift package.

You might also like...
Shows the issue with swift using an ObjC class which has a property from a swift package.

SwiftObjCSwiftTest Shows the issue with swift using an ObjC class which has a property from a swift package. The Swift class (created as @objc derived

Ios-App-ication-Swift - A simple iOS application made in Xcode using Swift
Ios-App-ication-Swift - A simple iOS application made in Xcode using Swift

📱 iPhone Calculator A simple iOS application made in Xcode using Swift. This ap

Save-the-dot-project-swift - Save the dot project with swift
Save-the-dot-project-swift - Save the dot project with swift

Save the Dot Apple introduced UIViewPropertyAnimator for iOS 10. We can use this

The Swift Package Index is the place to find Swift packages!
The Swift Package Index is the place to find Swift packages!

The Swift Package Index helps you make better decisions about the dependencies you use in your apps. The Swift Package Index is a search engine for pa

A stand-alone Swift wrapper around the mongo-c client library, enabling access to MongoDB servers.
A stand-alone Swift wrapper around the mongo-c client library, enabling access to MongoDB servers.

This package is deprecated in favour of the official Mongo Swift Driver. We advise users to switch to that pack

Elegant library to manage the interactions between view and model in Swift
Elegant library to manage the interactions between view and model in Swift

An assistant to manage the interactions between view and model ModelAssistant is a mediator between the view and model. This framework is tailored to

CRUD is an object-relational mapping (ORM) system for Swift 4+.

CRUD is an object-relational mapping (ORM) system for Swift 4+. CRUD takes Swift 4 Codable types and maps them to SQL database tables. CRUD can create tables based on Codable types and perform inserts and updates of objects in those tables. CRUD can also perform selects and joins of tables, all in a type-safe manner.

CoreXLSX is a Excel spreadsheet (XLSX) format parser written in pure Swift

CoreXLSX Excel spreadsheet (XLSX) format parser written in pure Swift CoreXLSX is a library focused on representing the low-level structure of the XML

Solutions to LeetCode by Swift
Solutions to LeetCode by Swift

LeetCode by Swift LeetCode Online Judge is a website containing many algorithm questions. Most of them are real interview questions of Google, Faceboo

Comments
  • Fix linux build

    Fix linux build

    On Linux, the @main struct cannot be in a library target that is then imported by the executable target. This works on macOS but raises the following build error on Linux:

    error: link command failed with exit code 1 (use -v to see invocation)
    /usr/bin/ld.gold: error: undefined symbol 'pg_extras_main' referenced in expression
    clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
    

    This work-around moves the top level command into the executable target.

    opened by finestructure 0
Owner
Sven A. Schmidt
Physicist & techie, independent software developer. Creator of the Swift Package Index.
Sven A. Schmidt
Build declarative GraphQL queries in Swift.

SociableWeaver Swift meets GraphQL in this lightweight, easy to use framework. SociableWeaver uses a declarative style of programming and makes GraphQ

Nicholas Bellucci 71 Nov 20, 2022
🔥 🔥 🔥Support for ORM operation,Customize the PQL syntax for quick queries,Support dynamic query,Secure thread protection mechanism,Support native operation,Support for XML configuration operations,Support compression, backup, porting MySQL, SQL Server operation,Support transaction operations.

?? ?? ??Support for ORM operation,Customize the PQL syntax for quick queries,Support dynamic query,Secure thread protection mechanism,Support native operation,Support for XML configuration operations,Support compression, backup, porting MySQL, SQL Server operation,Support transaction operations.

null 60 Dec 12, 2022
Sharing SQL queries between Server and Mobile databases

Sharing SQL queries between Server and Mobile databases Overview As we all know, code is expensive to maintain, and the more complex the code, the mor

Aaron LaBeau 4 May 24, 2022
A external macos application to generate and execute tuist commands

Tuist Menu Bar App An external macos application to generate and execute tuist commands. How it works? Parses all tasks and their arguments with the -

Aytug Sevgi 3 May 25, 2022
A proof-of-concept WebURL domain renderer, using a port of Chromium's IDN spoof-checking logic to protect against confusable domains

WebURLSpoofChecking A proof-of-concept WebURL.Domain renderer which uses a port of Chromium's IDN spoof-checking logic (Overview, Implementation) to p

Karl 3 Aug 6, 2022
Safe and easy wrappers for common Firebase Realtime Database functions.

FirebaseHelper FirebaseHelper is a small wrapper over Firebase's realtime database, providing streamlined methods for get, set, delete, and increment

Quan Vo 15 Apr 9, 2022
A fast, pure swift MongoDB driver based on Swift NIO built for Server Side Swift

A fast, pure swift MongoDB driver based on Swift NIO built for Server Side Swift. It features a great API and a battle-tested core. Supporting both MongoDB in server and embedded environments.

null 646 Dec 10, 2022
SQLite.swift - A type-safe, Swift-language layer over SQLite3.

SQLite.swift provides compile-time confidence in SQL statement syntax and intent.

Stephen Celis 8.7k Jan 3, 2023
🧡 SQLiteOrm-Swift is an ORM library for SQLite3 built with Swift 5

?? Easy to use SQLite ORM library written with Swift

Yevgeniy Zakharov 25 Oct 6, 2022
ObjectBox Swift - persisting your Swift objects superfast and simple

ObjectBox Swift ObjectBox is a superfast, light-weight object persistence framework. This Swift API seamlessly persists objects on-device for iOS and

ObjectBox 380 Dec 19, 2022