[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-81724":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":13,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":15,"stars7d":15,"stars30d":16,"stars90d":15,"forks30d":15,"starsTrendScore":15,"compositeScore":17,"rankGlobal":10,"rankLanguage":10,"license":18,"archived":19,"fork":19,"defaultBranch":20,"hasWiki":21,"hasPages":19,"topics":22,"createdAt":10,"pushedAt":10,"updatedAt":30,"readmeContent":31,"aiSummary":32,"trendingCount":15,"starSnapshotCount":15,"syncStatus":16,"lastSyncTime":33,"discoverSource":34},81724,"cosmo","mujib77\u002Fcosmo","mujib77","Cosmo is a terminal user interface (TUI) that provides real-time visibility into PostgreSQL database health, query performance, lock contention, and WAL\u002FMVCC internals. Built in Go.","",null,"Go",37,1,35,0,2,41.1,"MIT License",false,"main",true,[23,24,25,26,27,28,29],"bubbletea","golang","lipgloss","pgx-v5","postgresql","terminal","tui","2026-06-12 04:01:35","# Cosmo\n\n![License](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Flicense-MIT-blue)\n![Version](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fversion-v0.2.0-cyan)\n![Go](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FGo-1.26+-00ADD8)\n\nA real-time PostgreSQL internals dashboard for your terminal. Built in Go using Bubbletea and Lipgloss.\n\n![startup](Wi.gif)\n\n---\n\n## What is Cosmo?\n\nMost developers use PostgreSQL every day without actually knowing what's happening inside it. Cosmo fixes that.\n\nIt connects directly to your Postgres database and gives you a live view of everything — active queries, WAL activity, connection health, lock contention — all updating in real time, right in your terminal.\n\nNo browser. No external service. No configuration beyond a database URL. Just run it and watch your database breathe.\n\n---\n\n## Features\n\n**DB Overview panel**\n- Database name and PostgreSQL version\n- Database size\n- Active connections with visual progress bar\n- Cache hit ratio with visual progress bar and health colors\n- Server uptime\n- Total transaction count (comma formatted)\n\n**Active Queries panel**\n- Live view of all running queries\n- Query state (active, idle, idle in transaction)\n- Duration — how long each query has been running\n- Truncated query text\n\n**WAL & MVCC panel**\n- Current WAL LSN (Log Sequence Number)\n- Real-time WAL write rate in MB\u002Fs with progress bar\n- Dead tuples and live tuples\n- Checkpoint count\n- Last autovacuum time\n\n**Locks & Waits panel**\n- Active lock type and status (granted\u002Fwaiting)\n- Which table is locked\n- PID of the process holding or waiting for the lock\n- Query text\n\n**General**\n- Mission control boot sequence on startup\n- Auto-refreshes every 2 seconds\n- Health-based colors — green for healthy, amber for warning, red for critical\n- Live clock in header\n- TAB to switch between panels\n- R to manually refresh\n- Q to quit\n\n---\n\n## Demo\n\n![Demo](demo.gif)\n\nThe GIF shows:\n1. Cosmo booting up with the mission control startup animation\n2. The full dashboard appearing with all 4 panels populated with live data\n3. A `SELECT pg_sleep(20)` query being run in pgAdmin\n4. The query appearing live in the Active Queries panel with duration counting up\n5. The query finishing and disappearing from the panel\n\nTo record your own demo, use [ScreenToGif](https:\u002F\u002Fwww.screentogif.com\u002F) on Windows.\n\n---\n\n## Architecture\n\n```mermaid\nflowchart TD\n    A[PostgreSQL Database] --> B[pg_stat_activity]\n    A --> C[pg_stat_database]\n    A --> D[pg_stat_checkpointer]\n    A --> E[pg_locks]\n\n    B --> F[Cosmo — queries.go]\n    C --> F\n    D --> F\n    E --> F\n\n    F --> G[model.go — Bubbletea Model]\n    G -->|every 2 seconds| H[render.go — Lipgloss Renderer]\n\n    H --> I[DB Overview Panel]\n    H --> J[Active Queries Panel]\n    H --> K[WAL & MVCC Panel]\n    H --> L[Locks & Waits Panel]\n```\n\n### Project Structure\n\n```\ncosmo\u002F\n├── main.go                          → entry point, wires everything together\n├── config\u002F\n│   └── config.go                   → loads config from environment variables\n├── internal\u002F\n│   ├── db\u002F\n│   │   └── queries.go              → all PostgreSQL queries and data structs\n│   └── ui\u002F\n│       ├── model.go                → bubbletea model, tick loop, data fetching\n│       ├── render.go               → lipgloss rendering for all 4 panels\n│       ├── startup.go              → mission control boot sequence animation\n│       └── panels\u002F                 → reserved for future panel components\n```\n\n---\n\n## How it works\n\nCosmo queries PostgreSQL system views directly — the same views that Postgres uses internally to track its own state. These are:\n\n**pg_stat_activity** — every connection and what it's doing right now. This is how Cosmo shows active queries, their state, and how long they've been running.\n\n**pg_stat_database** — database-level statistics like cache hits, block reads, transaction counts, and database size. The cache hit ratio is calculated from blks_hit and blks_read.\n\n**pg_stat_checkpointer** — checkpoint statistics in PostgreSQL 17+. This is how Cosmo tracks how many checkpoints have happened.\n\n**pg_locks** — every lock currently held or waited on. Cosmo joins this with pg_stat_activity and pg_class to show which table is involved and what query is holding the lock.\n\n**WAL rate** is calculated by tracking the change in WAL LSN (Log Sequence Number) between refreshes. LSN is a byte position in the write-ahead log — by comparing two consecutive positions and dividing by elapsed time, Cosmo calculates the write throughput in MB\u002Fs.\n\nCosmo uses a connection pool via pgxpool to avoid connection conflicts when multiple queries run concurrently every 2 seconds.\n\n---\n\n## Setup\n\n**Requirements**\n- PostgreSQL 17+\n- Go 1.26+\n\n**Clone the repo**\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fmujib77\u002Fcosmo\ncd cosmo\n```\n\n**Create a .env file**\n\n```\nDATABASE_URL=postgres:\u002F\u002Fuser:password@localhost:5432\u002Fdbname\n```\n\n**Install dependencies**\n\n```bash\ngo mod tidy\n```\n\n**Run**\n\n```bash\ngo run main.go\n```\n\n---\n\n## Keyboard shortcuts\n\n| Key | Action |\n|-----|--------|\n| TAB | Switch active panel |\n| R | Manual refresh |\n| Q | Quit |\n\n---\n\n## Built With\n\n- [Go](https:\u002F\u002Fgolang.org\u002F) — systems language\n- [Bubbletea](https:\u002F\u002Fgithub.com\u002Fcharmbracelet\u002Fbubbletea) — TUI framework\n- [Lipgloss](https:\u002F\u002Fgithub.com\u002Fcharmbracelet\u002Flipgloss) — terminal styling\n- [pgx](https:\u002F\u002Fgithub.com\u002Fjackc\u002Fpgx) — PostgreSQL driver and connection pool\n\n---\n\n## License\n\nMIT — see [LICENSE](LICENSE)","Cosmo 是一个终端用户界面（TUI），为用户提供PostgreSQL数据库健康状况、查询性能、锁竞争以及WAL\u002FMVCC内部状态的实时可见性。项目采用Go语言开发，利用了Bubbletea和Lipgloss库来构建直观且响应迅速的界面。核心功能包括对活动查询、WAL活动、连接状态及锁等待情况的即时监控，并通过不同颜色直观展示系统健康程度。适用于需要直接从命令行环境中快速获取PostgreSQL运行状态信息的场景，如数据库维护、故障排查等，无需额外配置浏览器或外部服务，仅需提供数据库URL即可开始使用。","2026-06-11 04:06:06","CREATED_QUERY"]