Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation on storage parameters #312

Merged
merged 1 commit into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions conceptual/EFCore.PG/modeling/indexes.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ Note that each operator class is used for the corresponding index column, by ord
CREATE INDEX "IX_blogs_Id_Name" ON blogs ("Id", "Name" text_pattern_ops);
```

## Storage parameters

PostgreSQL allows configuring indexes with *storage parameters*, which can tweak their behaviors in various ways; which storage parameters are available depends on the chosen index method. [See the PostgreSQL documentation](https://www.postgresql.org/docs/current/sql-createindex.html#SQL-CREATEINDEX-STORAGE-PARAMETERS) for more information.

To configure a storage parameter on an index, use the following code:

```c#
protected override void OnModelCreating(ModelBuilder modelBuilder)
=> modelBuilder.Entity<Blog>()
.HasIndex(b => b.Url)
.HasStorageParameter("fillfactor", 70);
```

## Creating indexes concurrently

Creating an index can interfere with regular operation of a database. Normally PostgreSQL locks the table to be indexed against writes and performs the entire index build with a single scan of the table. Other transactions can still read the table, but if they try to insert, update, or delete rows in the table they will block until the index build is finished. This could have a severe effect if the system is a live production database. Very large tables can take many hours to be indexed, and even for smaller tables, an index build can lock out writers for periods that are unacceptably long for a production system.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Table and Column Naming
# Tables

## Naming

By default, EF Core will map to tables and columns named exactly after your .NET classes and properties, so an entity type named `BlogPost` will be mapped to a PostgreSQL table called `BlogPost`. While there's nothing wrong with that, the PostgreSQL world tends towards snake_case naming instead. In addition, any upper-case letters in unquoted identifiers are automatically converted to lower-case identifiers, so the Npgsql provider generates quotes around all such identifiers.

Expand Down Expand Up @@ -30,3 +32,14 @@ SELECT c.id, c.full_name
```

See the [plugin documentation](https://github.com/efcore/EFCore.NamingConventions) for more details,

## Storage parameters

PostgreSQL allows configuring tables with *storage parameters*, which can tweak storage behavior in various ways; [see the PostgreSQL documentation](https://www.postgresql.org/docs/current/sql-createtable.html#SQL-CREATETABLE-STORAGE-PARAMETERS) for more information.

To configure a storage parameter on a table, use the following code:

```c#
protected override void OnModelCreating(ModelBuilder modelBuilder)
=> modelBuilder.Entity<Blog>().HasStorageParameter("fillfactor", 70);
```
2 changes: 2 additions & 0 deletions conceptual/EFCore.PG/release-notes/8.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

New features will be documented later.

* Storage parameters can now be configured on indexes ([see docs](../modeling/indexes.md)), and storage parameters are now scaffolded from existing databases for both tables and indexes.

## Breaking changes

Note: version 8.0 of the lower-level Npgsql ADO.NET driver, which is used by the EF provider, also has some breaking changes. It's recommended to read the [release notes](../../Npgsql/release-notes/8.0.md) for that as well.
Expand Down
8 changes: 4 additions & 4 deletions conceptual/EFCore.PG/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
href: release-notes/1.1.md
- name: Creating a model
items:
- name: Table and column naming
href: modeling/table-column-naming.md
- name: Tables
href: modeling/tables.md
- name: Generated properties
href: modeling/generated-properties.md
- name: Concurrency tokens
href: modeling/concurrency.md
- name: Indexes
href: modeling/indexes.md
- name: Concurrency tokens
href: modeling/concurrency.md
- name: Mapping and translation
items:
- name: General
Expand Down