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

ORM engine initialization Error: migrate: Row size too large #9347

Closed
2 of 7 tasks
Whisprin opened this issue Dec 13, 2019 · 27 comments · Fixed by #10833
Closed
2 of 7 tasks

ORM engine initialization Error: migrate: Row size too large #9347

Whisprin opened this issue Dec 13, 2019 · 27 comments · Fixed by #10833
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented type/docs This PR mainly updates/creates documentation
Milestone

Comments

@Whisprin
Copy link
Contributor

Description

After upgrading from Gitea v1.9.5 to 1.10.0 I'm getting a database migration error:
ORM engine initialization attempt #8/10 failed. Error: migrate: do migrate: Error 1118: Row size too large. The maximum row size for the used table type, not counting BLOBs, is 8126. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs

@zeripath
Copy link
Contributor

What version of MySQL are you running?

@lunny lunny added the issue/needs-feedback For bugs, we need more details. For features, the feature must be described in more detail label Dec 15, 2019
@Whisprin
Copy link
Contributor Author

Whisprin commented Dec 15, 2019

@zeripath

% mariadb --version
mariadb  Ver 15.1 Distrib 10.4.11-MariaDB, for Linux (x86_64) using readline 5.1

gitea database collation: utf8mb4_unicode_ci
some tables are utf8mb4_unicode_ci, most are: utf8_general_ci

I remember there being a similar issue in Nextcloud before, requiring changing the table row format to DYNAMIC.

edit: This worked for me. Manually changing the row format and character set of each table:

# take a backup of the database

MariaDB> USE INFORMATION_SCHEMA;

# change row format
# this creates a list of SQL commands, run each manually
MariaDB> SELECT CONCAT("ALTER TABLE `", TABLE_SCHEMA,"`.`", TABLE_NAME, "` ROW_FORMAT=DYNAMIC;") AS MySQLCMD FROM TABLES WHERE TABLE_SCHEMA = "gitea";

# change collation, character set
# this creates a list of SQL commands, run each manually
MariaDB> SELECT CONCAT("ALTER TABLE `", TABLE_SCHEMA,"`.`", TABLE_NAME, "` CONVERT TO CHARACTER SET utf8mb4;") AS MySQLCMD FROM TABLES WHERE TABLE_SCHEMA = "gitea";

Adapted from: https://docs.nextcloud.com/server/11/admin_manual/maintenance/mysql_4byte_support.html#mariadb-support

@Whisprin
Copy link
Contributor Author

Whisprin commented Dec 15, 2019

@zeripath Why did you close this issue? I only described a manual workaround, the issue persists

This should be part of the database migration / maintenance script of gitea (see Nextcloud example). Apparently gitea requires a certain row format which is not explicitly specified during table creation.

Some more info: The mariadb defaults have changed in 10.2.2 and gitea required the newer values. However, previously existing tables need to be converted manually.
https://mariadb.com/kb/en/library/innodb-row-formats-overview/
https://mariadb.com/kb/en/library/innodb-file-format/

@zeripath zeripath reopened this Dec 15, 2019
@zeripath
Copy link
Contributor

As far as I could see the issue is specific to old versions of MariaDB. I'm but certain there's really any way we can go about detecting this.

@Whisprin
Copy link
Contributor Author

Whisprin commented Dec 16, 2019

The issue is independent of the MariaDB version in a sense that upgrading the database doesn't help. Specific MariaDB default configurations are required and tables which existed before need to be converted manually.
From my point of view gitea requires certain db features which are not explicitly specified or documented.

  • MariaDB specific documentation can be added in the docs
    • that's something I could work on
    • to mention the database server default ROW_FORMAT=DYNAMIC;
  • Prior to running migrations gitea can check the INFORMATION_SCHEMA table and print a meaningful warning
    • may be something I can contribute
  • An automatic migration can convert all gitea tables. There's no harm in converting tables, that are already in the correct format
    • all CREATE TABLE queries in gitea can be extend by ROW_FORMAT=DYNAMIC;

Only now (after I know the problem and workaround) I found the convert command:
https://github.com/go-gitea/gitea/pull/7144/files
A similar approach can be taken for the row format. (I can draft a PR)

The MySQL default charset could be changed to utf8mb4:
https://github.com/go-gitea/gitea/blob/master/custom/conf/app.ini.sample#L325

@stale
Copy link

stale bot commented Feb 14, 2020

This issue has been automatically marked as stale because it has not had recent activity. I am here to help clear issues left open even if solved or waiting for more insight. This issue will be closed if no further activity occurs during the next 2 weeks. If the issue is still valid just add a comment to keep it alive. Thank you for your contributions.

@stale stale bot added the issue/stale label Feb 14, 2020
@jacksgt
Copy link

jacksgt commented Feb 20, 2020

I just had the same issue upgrading from Gitea 1.10.2 to 1.11.1 with MariaDB version 10.3.22

This should really be part of the automatic upgrade process.

Thanks to @Whisprin for the SQL commands, they worked for me.

@stale stale bot removed the issue/stale label Feb 20, 2020
@sapk sapk added issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented and removed issue/needs-feedback For bugs, we need more details. For features, the feature must be described in more detail labels Feb 20, 2020
@sapk
Copy link
Member

sapk commented Feb 20, 2020

This should be added to the docs and maybe the check could be in doctor command first and if stable move to the web startup process.

@sapk sapk added the type/docs This PR mainly updates/creates documentation label Feb 20, 2020
@guillep2k
Copy link
Member

We could also add a function (step independent) to the migration function that attempts to create row with a deliberately big length, then delete it. If that fails, we could abort the process, warn the user and point them to the docs.

@leetNightshade
Copy link

I upgraded from 1.6 to 1.11 and am having this issue. I tried running the manual fix as suggested above, but I'm still seeing the same error.

2020/03/04 06:45:24 ...ations/migrations.go:330:Migrate() [I] Migration[77]: add theme to users 2020/03/04 06:45:24 ...orm/dialect_mysql.go:431:GetTables() [I] [SQL] SELECT TABLE_NAME, ENGINE, TABLE_ROWS, AUTO_INCREMENT, TABLE_COMMENTfromINFORMATION_SCHEMA.TABLESWHERETABLE_SCHEMA=? AND (ENGINE='MyISAM' OR ENGINE= 'InnoDB' ORENGINE= 'TokuDB') [gitea] 2020/03/04 06:45:24 ...orm/dialect_mysql.go:320:GetColumns() [I] [SQL] SELECTCOLUMN_NAME, IS_NULLABLE, COLUMN_DEFAULT, COLUMN_TYPE, COLUMN_KEY, EXTRA,COLUMN_COMMENTFROMINFORMATION_SCHEMA. COLUMNSWHERETABLE_SCHEMA= ? ANDTABLE_NAME= ? [gitea user] 2020/03/04 06:45:24 ...orm/dialect_mysql.go:460:GetIndexes() [I] [SQL] SELECTINDEX_NAME, NON_UNIQUE, COLUMN_NAMEFROMINFORMATION_SCHEMA.STATISTICSWHERETABLE_SCHEMA= ? ANDTABLE_NAME= ? [gitea user] 2020/03/04 06:45:24 .../xorm/session_raw.go:196:exec() [I] [SQL] ALTER TABLEuserADDtheme VARCHAR(30) DEFAULT '' NOT NULL ; - took: 3.750008ms 2020/03/04 06:45:24 routers/init.go:72:initDBEngine() [E] ORM engine initialization attempt #1/10 failed. Error: migrate: do migrate: Error 1118: Row size too large. The maximum row size for the used table type, not counting BLOBs, is 8126. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs

@guillep2k
Copy link
Member

@leetNightshade Can I suggest looking at these answers from SO?

@leetNightshade
Copy link

@leetNightshade Can I suggest looking at these answers from SO?

"Variable 'innodb_file_format' is a read only variable." Those answers aren't helpful to someone who doesn't know what they're doing. Gitea created this problem, why aren't you guys solving it?

@6543
Copy link
Member

6543 commented Mar 11, 2020

@leetNightshade what version of MySql do you run?

@guillep2k
Copy link
Member

@leetNightshade I'm sorry you didn't find that link useful. Unfortunately that's a limitation of MySQL/MariaDB. AFAICT the problem you are facing is very common for databases created with old versions of those products. "Modern" versions of MySQL/MariaDB don't have this problem. What you need to do is to upgrade your engine and look for a way of converting your tables to a newer format.

I'd suggest you perform a backup and upgrade to the latest database engine version possible (e.g. MariaDB 10.4.12). You can then export your database with mysqldump, modify the backup as instructed here, and import it back (you'll need to update the script and change DB="" for DB="gitea" or whatever is the name of your database).

@leetNightshade
Copy link

I'm running: mariadb Ver 15.1 Distrib 10.4.12-MariaDB, for Linux (x86_64) using readline 5.1

@6543
Copy link
Member

6543 commented Mar 12, 2020

@leetNightshade just try what guillep2k suggested and the try it again - would be nice if you can tell us the result

@guillep2k
Copy link
Member

I'm running: mariadb Ver 15.1 Distrib 10.4.12-MariaDB, for Linux (x86_64) using readline 5.1

Nice! 😄. The original poster had one, but I didn't know what you had.

So, you need to stop Gitea (make sure no gitea processes keep running, even if it seems to have stopped), and export/transform/re-import the database (assuming your database name is gitea):

mysqldump -u root -p gitea > original.sql
sed 's:ROW_FORMAT=COMPACT:ROW_FORMAT=DYNAMIC:g' original.sql > modified.sql
mysql -u root -p gitea < modified.sql

You will be prompted for the root user's password two times. The original.sql script remains as a normal backup in case of trouble. Save a copy of original.sql for safekeeping purposes.

@leetNightshade
Copy link

That did the trick, thank you @guillep2k !!

@zeripath
Copy link
Contributor

So we can finally close this issue - which is a fault with MySQL not Gitea - I guess we should put this little script in the FAQ.

@lunny lunny closed this as completed Mar 26, 2020
@Whisprin
Copy link
Contributor Author

It's not a fault with MySQL, it works as intended. It's a fault of how Gitea is using MySQL and a missing migration. If you need ROW_FORMAT=DYNAMIC specify it explicitly during table creation or at least please mention it in the documentation that dynamic is the expected row format. @zeripath @lunny

@lafriks
Copy link
Member

lafriks commented Mar 26, 2020

I created PR to set that for new installations and new tables. Existing tables won't be fixed and @guillep2k script should be used instead.

@lafriks lafriks reopened this Mar 26, 2020
@lafriks lafriks added this to the 1.12.0 milestone Mar 26, 2020
@Whisprin
Copy link
Contributor Author

Awesome @lafriks
Do you think it would be possible to add the migration or just a message to prompt the user to the doctor command as @sapk suggested earlier?

@lafriks
Copy link
Member

lafriks commented Mar 26, 2020

Migration is not really possible to implement as it requires dumping database and reimport. It would be enough to add that to FAQ as @zeripath suggested imho

@Whisprin
Copy link
Contributor Author

Using ALTER_TABLE the row format can be changed with MySQL built in commands without dumping and reimporting. See comment: #9347 (comment)

@devurandom
Copy link

# take a backup of the database

MariaDB> USE INFORMATION_SCHEMA;

# change row format
# this creates a list of SQL commands, run each manually
MariaDB> SELECT CONCAT("ALTER TABLE `", TABLE_SCHEMA,"`.`", TABLE_NAME, "` ROW_FORMAT=DYNAMIC;") AS MySQLCMD FROM TABLES WHERE TABLE_SCHEMA = "gitea";

# change collation, character set
# this creates a list of SQL commands, run each manually
MariaDB> SELECT CONCAT("ALTER TABLE `", TABLE_SCHEMA,"`.`", TABLE_NAME, "` CONVERT TO CHARACTER SET utf8mb4;") AS MySQLCMD FROM TABLES WHERE TABLE_SCHEMA = "gitea";

Thanks, @Whisprin, that worked and made my Gitea server usable again!

@zeripath
Copy link
Contributor

Or you could have just used gitea convert

https://docs.gitea.io/en-us/command-line/#convert

@mlthlschr
Copy link

mlthlschr commented Jul 31, 2020

did not work for me, neither using gitea convert, nor using the proposal of @Whisprin. Using gitea 1.12.3 and mariadb Ver 15.1 Distrib 10.4.12-MariaDB. EDIT: now it works, after the n-th try.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented type/docs This PR mainly updates/creates documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.